Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3308 มุมมอง

I have employee model, which I add contract records to via wizard:

from odoo import fields, models


class CreateEmployeeContract(models.TransientModel):
_name = 'create.employee.contract'
_description = 'Create employee contract wizard'

contract_number = fields.Integer(required=True)
start_date = fields.Date(required=True)
end_date = fields.Date(required=True)
employee_id = fields.Many2one('employees.employee')

def create_employee_contract_action(self):
self.env['employees.contract'].create({
'contract_number': self.contract_number,
'start_date': self.start_date,
'end_date': self.end_date,
'employee_id': 1
})

return True
How can I pass the current employee id(the one I'm adding contract to at the time)  instead of fixed value 1? (in ...create() 'employee_id')

The employee_id field isn't shown in the form view by design. So I want to get it from python.

อวตาร
ละทิ้ง

You can pass the employee id, in your action where you're opening the wizard itself. Then in your wizard, you can add the the default_get method and retrieve the value there

ผู้เขียน

Could you show me an example?

ผู้เขียน

Thanks for the idea. Now I pass context to the button:

<button
type="action"
name="%(create_employee_contract_action_view)d"
string="New contract"
context="{'employee_id': id}"
/>

and retrieve it in my wizard like so

'employee_id': self.env.context.get('employee_id')

Is this the right approach?

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ส.ค. 24
1528
0
ธ.ค. 24
1461
Import Data From Another Model แก้ไขแล้ว
1
มี.ค. 24
2512
1
มิ.ย. 23
12532
0
ม.ค. 23
3191