2017-02-16 2 views
0

odoo 10.0으로 "가입/로그인 양식"을 만들고 싶습니다. "Log_In()은 Odoo 10.0에서 정확히 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

내가 많이 검색 한, 그러나 아무도 없다 같은 상황. 나는 그런 오류를 정확히 이해하지 못한다.

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: 
    ... 

답변

1

그것은 확실히 말하기 어려운,하지만 스택 추적을 기반으로, 당신은 단지 **kwargs 하나를 받아 Log_In을해야 할 수도 있습니다 내 코드를 수정하고 나를 위해 작동합니다 :

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

문제는 그 프로그램이 'Account'및 'Password'가 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/ addons/point_of_sale/wizard/pos_details.py. 호출은 'self'를 인수로 사용하여'@ api.multi'를 사용하는 것처럼 보입니다. LienLac과 Matkhau는 Account와 Password 필드에 이미 값을 입력 할 수 있습니다. – Scovetta

+0

예, 바로 지원해 주신 –

0

+0

[Odoo Guidelines] (https://www.odoo.com/documentation/10.0/reference/guidelines.html) 및 [PEP8] (https : // www. .python.org/dev/peps/pep-0008 /) 코드를 리펙토링하십시오. – CZoellner