问题描述
我可以通过模型 2 中的按钮控制/改变模型 1 中状态栏的状态吗?
我的模型 1:bao_hiem.py 像这样:
name = fields.Many2one('hr.employee',string="Người lao động",>
required=True)
statea = fields.Selection([
('moi','MỚI'),('dangchay','ĐANG CHẠY'),('giamtamthoi','GIẢM TẠM THỜI'),('ketthuc','KẾT THÚC'),],default='moi')
stateb = fields.Selection([
('moi',default='dangchay')
thamchieu = fields.Char('Tham chiếu')
thoigian = fields.Date('Khoảng thời gian',default=datetime.today(),required=True)
bhxh = fields.Float('Mức đóng BHXH',readonly=True)
bhtn = fields.Float('Mức đóng BHTN',readonly=True)
bhyt = fields.Float('Mức đóng BHYT',readonly=True)
mucdongnld = fields.Float('% mức đóng của NLĐ',readonly=True)
mucdongcty = fields.Float('% mức đóng của Cty',readonly=True)
ngayhethan = fields.Date('Ngày hết hạn')
dkkhambenh = fields.Text('Nơi đăng ký khám chữa bệnh')
nguoilaodong_image = fields.Binary("Nguoilaodong Image",attachment=True,help="Nguoilaodong Image")
模型 2:dieu_chinh.py
name = fields.Many2one('hr.employee',string="Sổ bảo hiểm",required=True)
state = fields.Selection([
('moi',('daduocxacnhan','ĐÃ ĐƯỢC XÁC NHẬN'),('daduyet','ĐÃ DUYỆT'),('bihuy','BỊ HỦY'),default='moi')
thamchieu = fields.Char('Tham chiếu',required=True)
“确认”按钮可以像这样更改 XML 中的状态:
<record id="dieu_chinh_form_view" model="ir.ui.view">
<field name="name">dieu.chinh.form.view</field>
<field name="model">dieu.chinh</field>
<field name="arch" type="xml">
<form>
<header>
<button type="object" string="Confirm" name="confirm" states="moi" class="oe_highlight"/>
<button type="object" string="Cancel" states="daduocxacnhan" class="oe_highlight"/>
<button type="object" string="Accept" name="chapthuan" states="daduocxacnhan" class="oe_highlight"/>
<field name="state" widget="statusbar"></field>
</header>
请帮忙! 谢谢!
解决方法
<button type="object" name="action_change_state" string="Change State" class="oe_highlight"/>
def action_change_state(self):
# for each dieu.chinh the button was pressed on
for rec in self:
#find bao.hiem records to change,i cant see better link than name
bh = self.env["bao.hiem"].search([('name','=',rec.name)]) #it can find more than one record
if bh: # but it has to find at least one to write
bh.write({'statea': 'dangchay'})
return True