gpt4 book ai didi

python - 通过 Wizard Odoo 创造新的 One2many 记录

转载 作者:行者123 更新时间:2023-12-01 04:33:36 24 4
gpt4 key购买 nike

我想问一下,如何通过我的向导创建 One2many 记录?就像我有一个父类 A。在该表单上我创建了一个 One2many 字段。放置一个按钮(在父窗体上)来打开向导。该向导有一些选择字段。现在,当我设置选择字段并单击按钮(在向导上)时,我希望在父表单的 One2many 上创建过滤记录的所有结果。我不知道如何完成这件事。我的值从向导返回到父表单(简单字段),但我不知道在处理 One2many 字段时如何完成此操作。下面是我的父类和 One2many 关系类:

from openerp import models, fields, api
import openerp.exceptions

class hr_winter_module(models.Model):
_name = "hr.winter.module"
eligible_winter_ids = fields.One2many('hr.employee.winter.module', 'hr_winter_module_id', 'For Employee')
set_amount = fields.Float('VALUE')
my_name = fields.Char('NAME')
my_job = fields.Char('JOB')
my_country = fields.Char('COUNTRY')
proposal_date = fields.Date('Date of Proposal', required=True, default=fields.Date.today() )
_rec_name="proposal_date"


class hr_employee_winter_module(models.Model):

_name='hr.employee.winter.module'

@api.onchange('emp_name')
@api.depends('emp_name')
def myempl_name(self):
for myrec in self:
contract_records = myrec.env['hr.contract'].search([('employee_id','=', myrec.emp_name.id),('date_start','<=',fields.Date.today()),'|',('date_end','=',False),('date_end','>=',fields.Date.today())])
stable=False
if contract_records:
stable = contract_records[-1:].analytic_account_id.name
myrec.emp_stable= stable


hr_winter_module_id = fields.Many2one("hr.winter.module", "Employee", ondelete="cascade")
win_emp_name = fields.Many2one('hr.employee', string='Employee Name')
win_zeo_number = fields.Char(related='win_emp_name.zeo_number', string='ZEO Number', readonly=True )

这是我的向导代码:

from openerp import models, fields, api
import openerp.exceptions

class wizard_model(models.TransientModel):
_name = "wizard.model"

employee_type = fields.Selection([('muslim','Muslim'),('non-muslim','Non-Muslim'),('all','All')], default='all')
stable_id = fields.Many2many('account.analytic.account', 'employee_stable', 'id', 'analytic_account_id', 'Stables', domain=[('parent_id','=','Stables') ])
amount_for_all = fields.Float('Amount')
emp_name = fields.Char('Enter Name')
emp_job = fields.Char('Enter Job')
emp_country = fields.Char('Enter Nationalty')
@api.one
def set_val(self):
ids=self._ids
cr = self._cr
uid = self._uid
context = self._context
model_name=context.get('active_model')
form_id = context.get('active_id')
obj = self.pool.get(model_name).browse(cr,uid,form_id,context)

obj.set_amount=self.amount_for_all
obj.my_name = self.emp_name
obj.my_job = self.emp_job
obj.my_country = self.emp_country
self.pool.get('hr.winter.module').write(cr, uid, ids, {'eligible_winter_ids':[ (0, 0, {'win_emp_name':self.emp_name})]})

最佳答案

要在 one2many 字段中创建记录,只需将元组列表 [(0,0,{'field1':value, 'field2':value, ...})] 传递给父类write方法中的one2many字段,
例如: self.write( cr, uid, ids, {'one2many_field_name':[ (0, 0, {'field':value}) ] })

关于python - 通过 Wizard Odoo 创造新的 One2many 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32044609/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com