[IMP] timesheet_exception: narrow down when to _popup_exceptions() on write() calls

H11047
This commit is contained in:
percyhibou
2022-10-06 08:14:44 +00:00
parent 368dc65b4e
commit 6cdc24609f
3 changed files with 7 additions and 13 deletions

View File

@@ -6,8 +6,8 @@
<field name="description">Unit amount over 8 hrs</field> <field name="description">Unit amount over 8 hrs</field>
<field name="sequence">50</field> <field name="sequence">50</field>
<field name="model">account.analytic.line</field> <field name="model">account.analytic.line</field>
<field name="code">if timesheet.unit_amount > 8: failed=True</field> <field name="code">if self.unit_amount > 8: failed=True</field>
<field name="active" eval="False"/> <field name="active" eval="True"/>
</record> </record>
<record id="except_unit_amount_over_ordered_quantity" model="exception.rule"> <record id="except_unit_amount_over_ordered_quantity" model="exception.rule">
@@ -15,8 +15,8 @@
<field name="description">SO delivered qty plus unit amount exceeds ordered qty</field> <field name="description">SO delivered qty plus unit amount exceeds ordered qty</field>
<field name="sequence">50</field> <field name="sequence">50</field>
<field name="model">account.analytic.line</field> <field name="model">account.analytic.line</field>
<field name="code">if timesheet.so_line.product_template_id.service_policy == 'ordered_timesheet' and timesheet.so_line.qty_delivered + timesheet.unit_amount > timesheet.so_line.product_uom_qty: failed=True</field> <field name="code">if self.so_line.product_template_id.service_policy == 'ordered_timesheet' and self.so_line.qty_delivered + self.unit_amount > self.so_line.product_uom_qty: failed=True</field>
<field name="active" eval="False"/> <field name="active" eval="True"/>
</record> </record>
</odoo> </odoo>

View File

@@ -30,12 +30,6 @@ class AnalyticLine(models.Model):
res.detect_exceptions() res.detect_exceptions()
return res return res
@api.model
def _exception_rule_eval_context(self, rec):
res = super(AnalyticLine, self)._exception_rule_eval_context(rec)
res['timesheet'] = rec
return res
@api.model @api.model
def _reverse_field(self): def _reverse_field(self):
return 'timesheet_ids' return 'timesheet_ids'
@@ -43,7 +37,7 @@ class AnalyticLine(models.Model):
def write(self, vals): def write(self, vals):
if not vals.get('ignore_exception'): if not vals.get('ignore_exception'):
for timesheet in self: for timesheet in self:
if timesheet.detect_exceptions(): if timesheet.detect_exceptions() and 'stage_id' in vals:
return self._popup_exceptions() return self._popup_exceptions()
return super().write(vals) return super().write(vals)

View File

@@ -16,7 +16,7 @@ class TimesheetExceptionConfirm(models.TransientModel):
self.related_model_id.ignore_exception = True self.related_model_id.ignore_exception = True
res = super().action_confirm() res = super().action_confirm()
if self.ignore: if self.ignore:
return True return self.action_validate_timesheet()
else: else:
return res return res