0

I want to create a "Signup/Login Form" by odoo 10.0.

My code python :

class SinhVien(models.Model):   
     _name = "studentmanagement.sinhvien"

     Ten = fields.Char()
     GioiTinh = fields.Char()
     NgaySinh = fields.Char()
     LienLac = fields.Char()
     MatKhau = fields.Char()
     DiaChi = fields.Char()
     DangKyHocPhan = fields.Many2many('studentmanagement.khoahoc', 'Dang_Ky_Hoc_Phan', 'studentmanagement.sinhvien_id', 'studentmanagement.khoahoc_id', string ="dang ky hoc phan")
     _sql_constraints = [ ('LienLac', 'unique(LienLac)', 'Two student with the same user!') ]

     def Log_In(self, Account, Password):
         if Account is not None & Password is not None:
            test_prod_ids = self.search([('LienLac','=',Account),   ('MatKhau','=',Password)], limit=1, context=None)
            return {
              'name': ('My Profile'),
              'view_type': 'form',
              'view_mode': 'form',
              'res_model': 'studentmanagement.sinhvien',
              'view_id': False,
              'type': 'ir.actions.act_window',
            }
        else :
            return None
 class KhoaHoc(models.Model):
       _name = "studentmanagement.khoahoc"

       MonHoc = fields.Char()
       TinChi = fields.Integer()
       PhongHoc = fields.Char()
       GiaoVien = fields.Char()

LogIn_SignUp.xml :

    <record model="ir.ui.view" id="LogIn_form_view">
        <field name="name">Logging</field>
        <field name="model">studentmanagement.sinhvien</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Logging">
                <group>
                    <field name="LienLac"/>
                    <field name="MatKhau"/>
                    <button string="Log In" type="object" name="Log_In"/>
                </group>
            </form>
        </field>
    </record>

    <record model="ir.actions.act_window" id="LogIn_form_action">
        <field name="name">Log In</field>
        <field name="res_model">studentmanagement.sinhvien</field>
        <field name="view_type">form</field>
        <field name='view_id' ref='LogIn_form_view'/>
    </record>

    <menuitem id="main_menu_entrance" name="entrance"/>
    <menuitem id="Log In" name="Log In" parent="main_menu_entrance" action="LogIn_form_action"/>

Form : enter image description here And This is the error : enter image description here

I have searched a lot, but nobody have the same situation. I don't understand exactly such error, and how to resolve it.

Lee Dat
  • 155
  • 1
  • 6
  • 20

2 Answers2

1

It's hard to tell for sure, but based on the stack trace, you might need to have Log_In just accept a single **kwargs:

def Log_In(self, **kwargs):
    Account = kwargs.get('Account')
    Password = kwargs.get('Password')
    if Account is not None & Password is not None:
    ...

Or possibly just:

def Log_In(self, args):
    Account = args.get('Account')
    Password = args.get('Password')
    if Account is not None & Password is not None:
    ...
Community
  • 1
  • 1
Scovetta
  • 3,112
  • 1
  • 14
  • 13
  • The problem is that how the program can get text from 2 textbox fields in this : , if we are not sure 'Account' and 'Password' are 2 arguments referenced by 2 text fields – Lee Dat Feb 16 '17 at 06:00
  • There's an example in the Odoo documentation: https://github.com/odoo/odoo/blob/fc2e80cb4bcc450762c7ac5cb82a3e2d88062b38/addons/point_of_sale/wizard/pos_details.xml and https://github.com/odoo/odoo/blob/dae737eca119227cdc4f341c0766cab9caec48bb/addons/point_of_sale/wizard/pos_details.py. It looks like the calls use `@api.multi` with only `self` as an argument. The Account and Password fields might already get populated (are they LienLac and Matkhau)? – Scovetta Feb 16 '17 at 06:06
  • XML : Python : def Log_In(self, args): Account = args.get('LienLac') Password = args.get('MatKhau') – Lee Dat Feb 16 '17 at 07:08
0

I have corrected my code and it works for me :

def Log_In(self, args):
    Account = args.get('LienLac')
    Password = args.get('MatKhau')
    if Account is not None and Password is not None:
         test_prod_ids = self.search([('LienLac','=',Account),('MatKhau','=',Password)], limit=1, context=None)
         if test_prod_ids:
            return {
               'name': ('My Profile'),
               'view_type': 'form',
               'view_mode': 'form',
               'res_model': 'studentmanagement.sinhvien',
               'view_id': False,
               'type': 'ir.actions.act_window',
             }
       else:
          return None
    else :
         return None
Lee Dat
  • 155
  • 1
  • 6
  • 20
  • You really should consider to read [Odoo Guidelines](https://www.odoo.com/documentation/10.0/reference/guidelines.html) and [PEP8](https://www.python.org/dev/peps/pep-0008/) and refactor your code after it. – CZoellner Feb 16 '17 at 09:19