2017-02-16 91 views
0

我想通过odoo 10.0创建一个“注册/登录表单”。Odoo 10.0中的“Log_In()只需要3个参数(2给出)”

我的代码蟒蛇:

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"/> 

形式:enter image description here ,这是错误:enter image description here

我寻觅了很多,但没有人有同样的情况。我不明白这样的错误,以及如何解决它。

回答

1

这很难说是肯定的,但基于堆栈跟踪,你可能需要在Log_In只接受单一**kwargs

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

或者可能只是:

def Log_In(self, args): 
    Account = args.get('Account') 
    Password = args.get('Password') 
    if Account is not None & Password is not None: 
    ... 
+0

问题是如何程序可以如果我们不确定'帐户'和'密码'是2个文本字段引用的2个参数 –

+0

在Odoo文档中有一个示例:https://github.com/odoo/odoo/blob/fc2e80cb4bcc450762c7ac5cb82a3e2d88062b38/addons/point_of_sale/wizard/pos_details.xml和https://github.com/odoo/odoo/blob/dae737eca119227cdc4f341c0766cab9caec48bb/附加元件/ point_of_sale /向导/ pos_details.py。它看起来像调用使用'@ api.multi'只有'self'作为参数。帐户和密码字段可能已经填充(他们是LienLac和Matkhau)? – Scovetta

+0

是的,这是正确的 –

0

我有纠正我的代码,它适用于我:

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 
+0

您确实应该考虑阅读[Odoo指南](https://www.odoo.com/documentation/10.0/reference/guidelines.html)和[PEP8](https:// www .python.org/dev/peps/pep-0008 /),然后重构你的代码。 – CZoellner

相关问题