Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] sale_blanket_order_tier_validation: rely on computed state patch #14

Open
wants to merge 1 commit into
base: 17_add_sale_blanket_order_tier_validation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 14 additions & 39 deletions sale_blanket_order_tier_validation/models/sale_blanket_order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.tools import float_is_zero
from odoo import api, models


class SaleBlanketOrder(models.Model):
Expand All @@ -15,42 +14,18 @@ class SaleBlanketOrder(models.Model):
_state_to = ["open", "done", "expired"]

_tier_validation_manual_config = False
_tier_validation_state_field_is_computed = True

@api.depends(
"line_ids.remaining_uom_qty",
"validity_date",
"confirmed",
)
def _compute_state(self):
"""Complete override of Blanket Order Compute State Method:
The OCA Blanket Order module sets state via compute method which messes
with tier validation checks so we are going to instead set the state
to 'Open' only when clicking confirmed. This also forces process as before
just changing data would reset BO back to Open if expired."""
today = fields.Date.today()
precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
for order in self:
if not order.confirmed:
order.state = "draft"
elif order.validity_date <= today:
order.state = "expired"
elif float_is_zero(
sum(
order.line_ids.filtered(lambda line: not line.display_type).mapped(
"remaining_uom_qty"
)
),
precision_digits=precision,
):
order.state = "done"
# Removing else statement from original method
# else:
# order.state = "open"
@api.model
def _get_after_validation_exceptions(self):
return super()._get_after_validation_exceptions() + [
"confirmed",
"name",
]

def action_confirm(self):
"""Set the state to 'Open' when clicking confirmed instead of during compute."""
for rec in self:
rec.write({"state": "open"})
return super().action_confirm()
@api.model
def _get_under_validation_exceptions(self):
return super()._get_under_validation_exceptions() + [
"confirmed",
"name",
]
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def setUpClass(cls):
"model_id": cls.eco_model.id,
"review_type": "individual",
"reviewer_id": cls.test_user_1.id,
"definition_domain": "[('state', '=', 'draft')]",
}
)

Expand Down Expand Up @@ -105,13 +104,15 @@ def test02_validation_blanket_order(self):
}
)
self.assertEqual(blanket_order.state, "draft")
blanket_order.flush_recordset()

# Request tier validation
blanket_order.request_validation()

# Changing to new stage would cause a validation error
with self.assertRaises(ValidationError):
blanket_order.action_confirm()
blanket_order.flush_recordset()

# Validate the tier validation request
blanket_order.with_user(self.test_user_1).validate_tier()
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
odoo_test_helper
git+https://github.com/stefanrijnhart/[email protected]_tier_validation-computed_state_field#subdirectory=base_tier_validation