是否可以通过模型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', 'MỚI'),
        ('dangchay', 'ĐANG CHẠY'),
        ('giamtamthoi', 'GIẢM TẠM THỜI'),
        ('ketthuc', 'KẾT THÚC'),
        ],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', 'MỚI'),
        ('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>
 

请帮忙!谢谢!

Pax山雀
<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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章