【问题标题】:Is it possible to control/change state of statusbar in model 1 via a button in model 2? (Odoo 13)是否可以通过模型 2 中的按钮控制/更改模型 1 中状态栏的状态? (奥多 13)
【发布时间】:2020-12-25 08:09:07
【问题描述】:

我可以通过模型 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>
 

请帮忙! 谢谢!

【问题讨论】:

  • 您能否提供有关两个模型上的记录如何相关的信息。
  • 嗨,Paxmees,我提供了关于 XML 中的两个模型和按钮的详细信息。请帮忙。谢谢!
  • 是的,我明白了。感谢您的支持,Paxmees!

标签: odoo statusbar odoo-13


【解决方案1】:
<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

【讨论】:

    猜你喜欢
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多