diff --git a/purchase_blanket_order/README.rst b/purchase_blanket_order/README.rst
index b4bb880298f..7ef82500e6e 100644
--- a/purchase_blanket_order/README.rst
+++ b/purchase_blanket_order/README.rst
@@ -17,13 +17,13 @@ Purchase Blanket Orders
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
- :target: https://github.com/OCA/purchase-workflow/tree/15.0/purchase_blanket_order
+ :target: https://github.com/OCA/purchase-workflow/tree/16.0/purchase_blanket_order
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/purchase-workflow-15-0/purchase-workflow-15-0-purchase_blanket_order
+ :target: https://translation.odoo-community.org/projects/purchase-workflow-16-0/purchase-workflow-16-0-purchase_blanket_order
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
- :target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=15.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=16.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -100,7 +100,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues `_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -133,6 +133,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-This module is part of the `OCA/purchase-workflow `_ project on GitHub.
+This module is part of the `OCA/purchase-workflow `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/purchase_blanket_order/__manifest__.py b/purchase_blanket_order/__manifest__.py
index 9f9ec2047ab..4ba9e876107 100644
--- a/purchase_blanket_order/__manifest__.py
+++ b/purchase_blanket_order/__manifest__.py
@@ -5,7 +5,7 @@
"category": "Purchase",
"license": "AGPL-3",
"author": "ForgeFlow, Odoo Community Association (OCA)",
- "version": "15.0.2.0.1",
+ "version": "16.0.2.0.1",
"website": "https://github.com/OCA/purchase-workflow",
"summary": "Purchase Blanket Orders",
"depends": [
diff --git a/purchase_blanket_order/models/blanket_orders.py b/purchase_blanket_order/models/blanket_orders.py
index 0253e29ad9a..fdd2857a544 100644
--- a/purchase_blanket_order/models/blanket_orders.py
+++ b/purchase_blanket_order/models/blanket_orders.py
@@ -227,7 +227,7 @@ def onchange_partner_id(self):
self.fiscal_position_id = (
self.env["account.fiscal.position"]
.with_context(company_id=self.company_id.id)
- .get_fiscal_position(self.partner_id.id)
+ ._get_fiscal_position(partner=self.partner_id)
)
self.currency_id = (
@@ -329,7 +329,7 @@ def expire_orders(self):
[("state", "=", "open"), ("validity_date", "<=", today)]
)
expired_orders.modified(["validity_date"])
- expired_orders.recompute()
+ expired_orders.env.flush_all()
@api.model
def _search_original_uom_qty(self, operator, value):
diff --git a/purchase_blanket_order/models/purchase_order.py b/purchase_blanket_order/models/purchase_order.py
index b960efa8319..65f73a1fdca 100644
--- a/purchase_blanket_order/models/purchase_order.py
+++ b/purchase_blanket_order/models/purchase_order.py
@@ -126,11 +126,12 @@ def onchange_product_id(self):
return self.get_assigned_bo_line()
return res
- @api.onchange("product_qty", "product_uom")
- def _onchange_quantity(self):
- res = super()._onchange_quantity()
- if self.product_id and not self.env.context.get("skip_blanket_find", False):
- return self.get_assigned_bo_line()
+ @api.depends("product_qty", "product_uom")
+ def _compute_price_unit_and_date_planned_and_name(self):
+ res = super()._compute_price_unit_and_date_planned_and_name()
+ for rec in self:
+ if rec.product_id and not rec.env.context.get("skip_blanket_find", False):
+ return rec.get_assigned_bo_line()
return res
@api.onchange("blanket_order_line")
@@ -151,7 +152,9 @@ def onchange_blanket_order_line(self):
self.taxes_id = bol.taxes_id
else:
self._compute_tax_id()
- self.with_context(skip_blanket_find=True)._onchange_quantity()
+ self.with_context(
+ skip_blanket_find=True
+ )._compute_price_unit_and_date_planned_and_name()
@api.constrains("date_planned")
def check_date_planned(self):
diff --git a/purchase_blanket_order/static/description/index.html b/purchase_blanket_order/static/description/index.html
index 2ecebc29ec7..288001b01b7 100644
--- a/purchase_blanket_order/static/description/index.html
+++ b/purchase_blanket_order/static/description/index.html
@@ -1,4 +1,3 @@
-
@@ -369,7 +368,7 @@ Purchase Blanket Orders
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7237471164928b8665c603ac9943005b2d6332ed46da07c0dd2e40b0862a793c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
A purchase blanket order is a pre-agreement to purchase a certain number of
quantities of products at a specific price. From a confirmed blanket order,
the users can create new purchase orders at such price, until the blanket
@@ -437,7 +436,7 @@
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-feedback.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -464,7 +463,7 @@
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-
This module is part of the OCA/purchase-workflow project on GitHub.
+
This module is part of the OCA/purchase-workflow project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/purchase_blanket_order/tests/test_purchase_blanket_order.py b/purchase_blanket_order/tests/test_purchase_blanket_order.py
index dbb9f2259e0..dce5a6b2641 100644
--- a/purchase_blanket_order/tests/test_purchase_blanket_order.py
+++ b/purchase_blanket_order/tests/test_purchase_blanket_order.py
@@ -14,6 +14,9 @@ def setUp(self):
self.blanket_order_line_obj = self.env["purchase.blanket.order.line"]
self.blanket_order_wiz_obj = self.env["purchase.blanket.order.wizard"]
+ self.user_test = self.env["res.users"].create(
+ {"name": "Test user", "login": "test_login"}
+ )
self.partner = self.env["res.partner"].create(
{"name": "TEST SUPPLIER", "supplier_rank": 1}
)
@@ -21,7 +24,7 @@ def setUp(self):
# Seller IDS
seller = self.env["product.supplierinfo"].create(
- {"name": self.partner.id, "price": 30.0}
+ {"partner_id": self.partner.id, "price": 30.0}
)
self.product = self.env["product.product"].create(
@@ -111,7 +114,7 @@ def test_01_create_blanket_order_flow(self):
blanket_order._search_received_uom_qty(">=", 0.0)
blanket_order._search_remaining_uom_qty(">=", 0.0)
- def test__02_create_purchase_orders_from_blanket_order(self):
+ def test_02_create_purchase_orders_from_blanket_order(self):
"""We create a blanket order and create two purchase orders"""
blanket_order = self.blanket_order_obj.create(
{
@@ -226,3 +229,51 @@ def test_03_create_purchase_orders_from_blanket_order_line(self):
self.assertEqual(bo_lines[0].remaining_uom_qty, 10.0)
self.assertEqual(bo_lines[1].remaining_uom_qty, 30.0)
+
+ def test_04_constraints_blanket_order(self):
+ """We create a blanket order and check constraints"""
+ blanket_order = self.blanket_order_obj.create(
+ {
+ "partner_id": self.partner.id,
+ "partner_ref": "REF",
+ "validity_date": fields.Date.to_string(self.tomorrow),
+ "payment_term_id": self.payment_term.id,
+ "line_ids": [
+ (
+ 0,
+ 0,
+ {
+ "product_id": self.product.id,
+ "product_uom": self.product.uom_id.id,
+ "original_uom_qty": 20.0,
+ "price_unit": 30.0,
+ },
+ )
+ ],
+ }
+ )
+ blanket_order.write({"partner_id": False})
+ blanket_order.onchange_partner_id()
+ self.assertFalse(blanket_order.payment_term_id)
+ self.assertFalse(blanket_order.fiscal_position_id)
+
+ self.partner.user_id = self.user_test
+ blanket_order.write({"partner_id": self.partner.id})
+ blanket_order.onchange_partner_id()
+ self.assertEqual(blanket_order.user_id, self.user_test)
+ blanket_order.sudo().action_confirm()
+ self.assertEqual(blanket_order.state, "open")
+
+ # remove open BO
+ with self.assertRaises(UserError):
+ blanket_order.sudo().unlink()
+
+ wizard1 = self.blanket_order_wiz_obj.with_context(
+ active_id=blanket_order.id, active_model="purchase.blanket.order"
+ ).create({})
+ wizard1.line_ids[0].write({"qty": 10.0})
+ wizard1.sudo().create_purchase_order()
+
+ # cancel BO with PO not cancelled
+ with self.assertRaises(UserError):
+ blanket_order.sudo().action_cancel()
diff --git a/purchase_blanket_order/tests/test_purchase_order.py b/purchase_blanket_order/tests/test_purchase_order.py
index b835f02f9ad..50f42ff08c9 100644
--- a/purchase_blanket_order/tests/test_purchase_order.py
+++ b/purchase_blanket_order/tests/test_purchase_order.py
@@ -21,7 +21,7 @@ def setUp(self):
# Seller IDS
seller = self.env["product.supplierinfo"].create(
- {"name": self.partner.id, "price": 30.0}
+ {"partner_id": self.partner.id, "price": 30.0}
)
self.product = self.env["product.product"].create(
diff --git a/purchase_blanket_order/views/purchase_blanket_order_views.xml b/purchase_blanket_order/views/purchase_blanket_order_views.xml
index 92e25d0ac8d..b6f320dfaab 100644
--- a/purchase_blanket_order/views/purchase_blanket_order_views.xml
+++ b/purchase_blanket_order/views/purchase_blanket_order_views.xml
@@ -112,6 +112,7 @@
groups="base.group_multi_company"
options="{'no_create': True}"
/>
+
diff --git a/purchase_blanket_order/views/purchase_order_views.xml b/purchase_blanket_order/views/purchase_order_views.xml
index d3290e33d4a..f635a650293 100644
--- a/purchase_blanket_order/views/purchase_order_views.xml
+++ b/purchase_blanket_order/views/purchase_order_views.xml
@@ -30,13 +30,13 @@
>purchase.order.from.blanket.form - disable adding lines
purchase.order
-
blanket_order_id==False
+
diff --git a/purchase_blanket_order/wizard/create_purchase_orders.xml b/purchase_blanket_order/wizard/create_purchase_orders.xml
index b2997f3a497..7750a32d78f 100644
--- a/purchase_blanket_order/wizard/create_purchase_orders.xml
+++ b/purchase_blanket_order/wizard/create_purchase_orders.xml
@@ -5,7 +5,7 @@
purchase.blanket.order.wizard