From c3e5612018c7c229ee751219aed69792f45eb647 Mon Sep 17 00:00:00 2001 From: ThiagoMForgeFlow Date: Thu, 18 Jan 2024 12:50:27 +0100 Subject: [PATCH] [MIG] purchase_blanket_order: Migration to 16.0 --- purchase_blanket_order/README.rst | 10 +-- purchase_blanket_order/__manifest__.py | 2 +- .../models/blanket_orders.py | 8 +- .../models/purchase_config_settings.py | 2 +- .../models/purchase_order.py | 19 +++-- .../static/description/index.html | 7 +- .../tests/test_purchase_blanket_order.py | 76 ++++++++++++++++++- .../tests/test_purchase_order.py | 17 ++++- .../views/purchase_blanket_order_views.xml | 1 + .../views/purchase_config_settings.xml | 2 +- .../views/purchase_order_views.xml | 8 +- .../wizard/create_purchase_orders.xml | 4 +- 12 files changed, 121 insertions(+), 35 deletions(-) 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..acd2da03c53 100644 --- a/purchase_blanket_order/models/blanket_orders.py +++ b/purchase_blanket_order/models/blanket_orders.py @@ -13,10 +13,6 @@ class BlanketOrder(models.Model): _description = "Purchase Blanket Order" _order = "date_start desc, id desc" - @api.model - def _default_currency(self): - return self.env.user.company_id.currency_id - @api.model def _default_company(self): return self.env.user.company_id @@ -227,7 +223,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 +325,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_config_settings.py b/purchase_blanket_order/models/purchase_config_settings.py index 30c695fe6ff..e6ed88ea6b9 100644 --- a/purchase_blanket_order/models/purchase_config_settings.py +++ b/purchase_blanket_order/models/purchase_config_settings.py @@ -8,7 +8,7 @@ class PurchaseConfigSettings(models.TransientModel): _inherit = "res.config.settings" group_purchase_blanket_disable_adding_lines = fields.Boolean( - string="Disable adding more lines to SOs", + string="Disable adding more lines to POs", implied_group="purchase_blanket_order." "purchase_blanket_orders_disable_adding_lines", ) diff --git a/purchase_blanket_order/models/purchase_order.py b/purchase_blanket_order/models/purchase_order.py index b960efa8319..432c5b9b7e9 100644 --- a/purchase_blanket_order/models/purchase_order.py +++ b/purchase_blanket_order/models/purchase_order.py @@ -66,7 +66,9 @@ class PurchaseOrderLine(models.Model): _inherit = "purchase.order.line" blanket_order_line = fields.Many2one( - comodel_name="purchase.blanket.order.line", copy=False + comodel_name="purchase.blanket.order.line", + copy=False, + domain="[('product_id', '=', product_id)]", ) def _get_assigned_bo_line(self, bo_lines): @@ -126,11 +128,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 +154,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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

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 @@

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.

@@ -464,7 +463,7 @@

Maintainers

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..48e36724332 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( @@ -33,6 +36,7 @@ def setUp(self): "type": "consu", "uom_id": self.env.ref("uom.product_uom_unit").id, "default_code": "PROD_DEL01", + "description_purchase": "Purchase Description", } ) self.product2 = self.env["product.product"].create( @@ -65,18 +69,26 @@ def test_01_create_blanket_order_flow(self): 0, { "product_id": self.product.id, - "product_uom": self.product.uom_id.id, "original_uom_qty": 20.0, "price_unit": 0.0, # will be updated later + "product_uom": self.product.uom_id.id, }, ) ], } ) blanket_order.sudo().onchange_partner_id() + blanket_order.line_ids[0].write({"product_uom": False}) blanket_order.line_ids[0].sudo().onchange_product() blanket_order._compute_line_count() blanket_order._compute_uom_qty() + name = ( + "[{}] {}".format(self.product.name, self.product.code) + + "\n" + + self.product.description_purchase + ) + self.assertEqual(blanket_order.line_ids[0].name, name) + self.assertEqual(blanket_order.line_ids[0].product_uom, self.product.uom_id) self.assertEqual(blanket_order.state, "draft") self.assertEqual(blanket_order.line_ids[0].price_unit, 30.0) @@ -111,7 +123,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 +238,61 @@ 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}) + res = wizard1.sudo().create_purchase_order() + po = self._get_po_from_wizard(res) + + # cancel BO with PO not cancelled + with self.assertRaises(UserError): + blanket_order.sudo().action_cancel() + + po.button_cancel() + blanket_order.sudo().action_cancel() + + with self.assertRaises(UserError): + # Blanket order expired + self.blanket_order_wiz_obj.with_context( + active_id=blanket_order.id, active_model="purchase.blanket.order" + ).create({}) diff --git a/purchase_blanket_order/tests/test_purchase_order.py b/purchase_blanket_order/tests/test_purchase_order.py index b835f02f9ad..4051b5bdd20 100644 --- a/purchase_blanket_order/tests/test_purchase_order.py +++ b/purchase_blanket_order/tests/test_purchase_order.py @@ -3,6 +3,7 @@ from datetime import date, timedelta from odoo import fields +from odoo.exceptions import ValidationError from odoo.tests import common @@ -17,11 +18,14 @@ def setUp(self): self.partner = self.env["res.partner"].create( {"name": "TEST SUPPLIER", "supplier_rank": 1} ) + self.partner_2 = self.env["res.partner"].create( + {"name": "TEST SUPPLIER 2", "supplier_rank": 2} + ) self.payment_term = self.env.ref("account.account_payment_term_30days") # 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( @@ -49,6 +53,9 @@ def setUp(self): self.validity = date.today() + timedelta(days=365) self.date_schedule_1 = date.today() + timedelta(days=10) self.date_schedule_2 = date.today() + timedelta(days=20) + self.currency_test = self.env["res.currency"].create( + {"name": "Test Currency", "symbol": "T"} + ) def create_blanket_order_01(self): blanket_order = self.blanket_order_obj.create( @@ -200,3 +207,11 @@ def test_02_create_purchase_order(self): ] ) self.assertEqual(po_line.blanket_order_line, bo_line_assigned) + + # change currency of the PO line + with self.assertRaises(ValidationError): + po.write({"currency_id": self.currency_test}) + + # change partner of the PO line + with self.assertRaises(ValidationError): + po.write({"partner_id": self.partner_2}) 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_config_settings.xml b/purchase_blanket_order/views/purchase_config_settings.xml index ae30a49aaa3..a9657d84ee2 100644 --- a/purchase_blanket_order/views/purchase_config_settings.xml +++ b/purchase_blanket_order/views/purchase_config_settings.xml @@ -23,7 +23,7 @@
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
- +
@@ -18,7 +18,7 @@ - +