如何解决是否可以通过模型 2 中的按钮控制/更改模型 1 中状态栏的状态? (Odoo 13)
我可以通过模型 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。