odoo - 是否可以通过模型 2 中的按钮控制/更改模型 1 中状态栏的状态? (奥杜 13)

标签 odoo statusbar 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>
 

请帮忙! 谢谢!

最佳答案

<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

关于odoo - 是否可以通过模型 2 中的按钮控制/更改模型 1 中状态栏的状态? (奥杜 13),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65446353/

相关文章:

docker - 将Docker容器及其数据库容器移动到另一台服务器

javascript - Odoo 数据透视报告错误值被转换为 "Undefined"

odoo - 在 openerp 中确认一个条件对话框和动态文本

python - Odoo 13 如何通过 api 运行操作?

android - 仅在一个 fragment 中隐藏状态栏并在其他 fragment 中显示

IOS 11.2 Cordova Inappbrowser 在方向更改上添加了灰色 block

ubuntu - 如何在 Odoo 13 中指定自定义插件目录?

templates - Odoo <t t-call ="website.layout"> qWebException

html - Odoo 和 Qweb : render HTML in quotation report

ios - 状态栏区域未检测到点击手势?