我有一个名为Vehicle的模型,我创建了一个向导od_add_new_vehicle。 在向导的xml视图中,我创建了一个动作。 如何将Vehicle模型与向导链接,以便我可以永久保存数据
class Vehicle(models.Model):
_name = 'transport.vehicle'
name = fields.Char(string="Name", required=True)
description = fields.Text()
reg_date = fields.Date()
department = fields.Char()
available = fields.Boolean()
class od_add_new_vehicle(models.TransientModel):
_name = 'od.add.new.vehicle'
_description = 'Add new vehicle'
name = fields.Char('vehicle name')
description = fields.Text('Description')
reg_date = fields.Date('Reg date')
department = fields.Char('Department')
available = fields.Boolean('Available')
def _default_veh(self):
return self.env['transport.vehicle'].browse(self._context.get('active_ids'))
v_id = fields.Many2one('transport.vehicle', string="Vehicle ref", required=True, default=_default_veh)
@api.multi
def od_add_book(self):
self.v_id.name = self.name
self.v_id.description = self.description
self.v_id.reg_date = self.reg_date
self.v_id.department = self.department
self.v_id.available = self.available
self.v_id.member_id = self.member_id
return {}
答案 0 :(得分:2)
以下是从向导更新/插入数据的简单方法。
例如:
<footer>
<button name="insert_data" string="Insert/Update data" type="object"
class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
.py边功能
@api.multi
def insert_data(self):
for record in self.env['target.table.name'].browse(self._context.get('active_ids', [])):
#here you can access target table fields using *record* variable
record.field_name = wizard.field_name
return True