首页 > 解决方案 > Odoo V11 - 如何强制手动编辑计算字段?

问题描述

我在“hr.payslip”模型中有一个计算字段。

cumulative_income_tax_base_previous = fields.Float(string="Kümülatif 
   Gelir Vergisi Matrahı" 
   compute='_get_previous_payslip_fields',store=True)

我想根据同一模型中的另一个字段(类型为布尔值)编辑此字段。

first_access = fields.Boolean(string="İlk bordro girişi mi ?", 
default=False)

如果此字段设置为 true,我想编辑手动计算字段。在表单视图中,我将 readonly:True 属性设置为我的计算字段。

<xpath expr="//group[@name='accounting']" position="after">
   <group name="other_calculation" string="Dİğer Hesaplamalar">
       <field name="first_access"/>
       <field name="cumulative_income_tax_base_previous"
            attrs="{'readonly':[('first_access', '!=', True)], 
                    'required': [('first_access', '=', True)]}"/>

   </group>
 </xpath>

但是,我没有在 python 类中制作。当我手动编辑它时,它被分配为零。我怎么解决这个问题

@api.one
@api.depends('employee_id', 'date_from', 'date_to', 'first_access')
def _get_previous_payslip_fields(self):            
 for record in self:
    if record.employee_id and record.date_from and record.date_to 
          and not record.line_ids:

        .... (some codes)

        payslip_object = self.env['hr.payslip'].search(domain, 

        order='id desc', limit=1)


        if payslip_object and not record.first_access:  

          record.gv_rate_init_previous=payslip_object['gv_rate_init']

          record.cumulative_income_tax_base_previous = 
                   payslip_object['cumulative_income_tax_base']
        else:
             ... ? ( When the first access field is set True)

标签: pythonpython-3.xodooodoo-11

解决方案


只需添加 xml force_save="1",并在 Python 中 store = True:例如:

  1. XML:

    <field name="your_field"  force_save="1"/>
    
  2. Python:

    your_fields = fields.Float("Your field", compute=compute_method, store=True)
    

推荐阅读