Skip to content

Commit

Permalink
[FIX] sale_exception : so line decoration-danger condition
Browse files Browse the repository at this point in the history
  • Loading branch information
glitchov committed May 4, 2023
1 parent 862020a commit 3d77b85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
8 changes: 8 additions & 0 deletions sale_exception/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class SaleOrderLine(models.Model):
ignore_exception = fields.Boolean(
related="order_id.ignore_exception", store=True, string="Ignore Exceptions"
)
is_exception_danger = fields.Boolean(compute="_compute_is_exception_danger")

@api.depends("exception_ids", "ignore_exception")
def _compute_is_exception_danger(self):
for rec in self:
rec.is_exception_danger = (
len(rec.exception_ids) > 0 and not rec.ignore_exception
)

@api.depends("exception_ids", "ignore_exception")
def _compute_exceptions_summary(self):
Expand Down
6 changes: 5 additions & 1 deletion sale_exception/tests/test_multi_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ def test_sale_order_exception(self):
)

orders = so1 + so2 + so3
# ensure init state
for order in orders:
# ensure init state
self.assertTrue(order.state == "draft")
self.assertTrue(len(order.exception_ids) == 0)
self.assertFalse(so1.order_line[0].is_exception_danger)
self.assertFalse(so3.order_line[0].is_exception_danger)

self.env["sale.order"].test_all_draft_orders()

# basic tests

self.assertTrue(so1.state == "draft")
self.assertTrue(len(so1.exception_ids) == 0)
self.assertFalse(so1.order_line[0].is_exception_danger)

self.assertTrue(so2.state == "draft")
self.assertTrue(exception_no_sol in so2.exception_ids)
Expand All @@ -97,6 +100,7 @@ def test_sale_order_exception(self):
"</ul>"
),
)
self.assertTrue(so3.order_line[0].is_exception_danger)

# test return value of detect_exception()

Expand Down
7 changes: 2 additions & 5 deletions sale_exception/views/sale_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,10 @@
</div>
</xpath>
<xpath expr="//field[@name='order_line']/tree" position="inside">
<field name="exception_ids" invisible="1" />
<field name="ignore_exception" invisible="1" />
<field name="is_exception_danger" invisible="1" />
</xpath>
<xpath expr="//field[@name='order_line']/tree" position="attributes">
<attribute
name="decoration-danger"
>not ignore_exception and exception_ids</attribute>
<attribute name="decoration-danger">is_exception_danger</attribute>
</xpath>
</field>
</record>
Expand Down

0 comments on commit 3d77b85

Please sign in to comment.