diff --git a/purchase_operating_unit/__manifest__.py b/purchase_operating_unit/__manifest__.py index a46cd5db9b..1eac69b4e6 100644 --- a/purchase_operating_unit/__manifest__.py +++ b/purchase_operating_unit/__manifest__.py @@ -7,7 +7,7 @@ "name": "Operating Unit in Purchase Orders", "summary": "Adds the concecpt of operating unit (OU) in purchase order " "management", - "version": "15.0.1.2.0", + "version": "17.0.1.0.0", "author": "ForgeFlow, " "Serpent Consulting Services Pvt. Ltd.," "Odoo Community Association (OCA)", diff --git a/purchase_operating_unit/models/account_move.py b/purchase_operating_unit/models/account_move.py index 17e4933d6e..75a6149e31 100644 --- a/purchase_operating_unit/models/account_move.py +++ b/purchase_operating_unit/models/account_move.py @@ -2,17 +2,13 @@ # - Jordi Ballester Alomar # Copyright 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from odoo import _, api, fields, models +from odoo import _, api, models from odoo.exceptions import ValidationError class AccountMove(models.Model): _inherit = "account.move" - purchase_ou_domain = fields.Many2many( - comodel_name="purchase.order", compute="_compute_purchase_ou_domain" - ) - # Load all unsold PO lines @api.onchange("purchase_vendor_bill_id", "purchase_id") def _onchange_purchase_auto_complete(self): @@ -27,15 +23,6 @@ def _onchange_purchase_auto_complete(self): self.operating_unit_id = purchase_id.operating_unit_id.id return super()._onchange_purchase_auto_complete() - @api.depends("operating_unit_id") - def _compute_purchase_ou_domain(self): - for rec in self: - rec.purchase_ou_domain = ( - self.env["purchase.order"] - .sudo() - .search([("operating_unit_id", "=", rec.operating_unit_id.id)]) - ) - class AccountMoveLine(models.Model): _inherit = "account.move.line" diff --git a/purchase_operating_unit/models/purchase_order.py b/purchase_operating_unit/models/purchase_order.py index 07810dfe0a..132e41944c 100644 --- a/purchase_operating_unit/models/purchase_order.py +++ b/purchase_operating_unit/models/purchase_order.py @@ -9,27 +9,19 @@ class PurchaseOrder(models.Model): _inherit = "purchase.order" - READONLY_STATES = { - "purchase": [("readonly", True)], - "done": [("readonly", True)], - "cancel": [("readonly", True)], - } - operating_unit_id = fields.Many2one( comodel_name="operating.unit", string="Operating Unit", - states=READONLY_STATES, default=lambda self: ( - self.env["res.users"].operating_unit_default_get(self.env.uid) + self.env["res.users"]._get_default_operating_unit(self.env.uid) ), ) requesting_operating_unit_id = fields.Many2one( comodel_name="operating.unit", string="Requesting Operating Unit", - states=READONLY_STATES, default=lambda self: ( - self.env["res.users"].operating_unit_default_get(self.env.uid) + self.env["res.users"]._get_default_operating_unit(self.env.uid) ), ) diff --git a/purchase_operating_unit/tests/test_purchase_operating_unit.py b/purchase_operating_unit/tests/test_purchase_operating_unit.py index 3cb596fd8e..14aedf2852 100644 --- a/purchase_operating_unit/tests/test_purchase_operating_unit.py +++ b/purchase_operating_unit/tests/test_purchase_operating_unit.py @@ -10,55 +10,56 @@ class TestPurchaseOperatingUnit(common.TransactionCase): - def setUp(self): - super().setUp() - self.ResUsers = self.env["res.users"] - self.PurchaseOrder = self.env["purchase.order"] - self.AccountInvoice = self.env["account.move"] - self.AccountAccount = self.env["account.account"] + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.ResUsers = cls.env["res.users"] + cls.PurchaseOrder = cls.env["purchase.order"] + cls.AccountInvoice = cls.env["account.move"] + cls.AccountAccount = cls.env["account.account"] # company - self.company = self.env.ref("base.main_company") + cls.company = cls.env.ref("base.main_company") # groups - self.group_purchase_user = self.env.ref("purchase.group_purchase_user") + cls.group_purchase_user = cls.env.ref("purchase.group_purchase_user") # Main Operating Unit - self.ou1 = self.env.ref("operating_unit.main_operating_unit") + cls.ou1 = cls.env.ref("operating_unit.main_operating_unit") # B2B Operating Unit - self.b2b = self.env.ref("operating_unit.b2b_operating_unit") + cls.b2b = cls.env.ref("operating_unit.b2b_operating_unit") # Partner - self.partner1 = self.env.ref("base.res_partner_1") + cls.partner1 = cls.env.ref("base.res_partner_1") # Products - self.product1 = self.env.ref("product.product_product_7") - self.product2 = self.env.ref("product.product_product_9") - self.product3 = self.env.ref("product.product_product_11") + cls.product1 = cls.env.ref("product.product_product_7") + cls.product2 = cls.env.ref("product.product_product_9") + cls.product3 = cls.env.ref("product.product_product_11") # Account - payable_acc_type = self.env.ref("account.data_account_type_payable").id - self.account = self.AccountAccount.search( - [("user_type_id", "=", payable_acc_type)], limit=1 + cls.account = cls.AccountAccount.search( + [("account_type", "=", "liability_payable")], limit=1 ) # Create users - self.user1_id = self._create_user( + cls.user1_id = cls._create_user( "user_1", - [self.group_purchase_user], - self.company, - [self.ou1], + [cls.group_purchase_user], + cls.company, + [cls.ou1], ) - self.user2_id = self._create_user( + cls.user2_id = cls._create_user( "user_2", - [self.group_purchase_user], - self.company, - [self.b2b], + [cls.group_purchase_user], + cls.company, + [cls.b2b], ) - self.purchase1 = self._create_purchase( - self.user1_id, - [(self.product1, 1000), (self.product2, 500), (self.product3, 800)], + cls.purchase1 = cls._create_purchase( + cls.user1_id, + [(cls.product1, 1000), (cls.product2, 500), (cls.product3, 800)], ) - self.purchase1.with_user(self.user1_id).button_confirm() - self.invoice = self._create_invoice(self.purchase1, self.partner1, self.account) + cls.purchase1.with_user(cls.user1_id).button_confirm() + cls.invoice = cls._create_invoice(cls.purchase1, cls.partner1, cls.account) - def _create_user(self, login, groups, company, operating_units): + @classmethod + def _create_user(cls, login, groups, company, operating_units): """Create a user.""" group_ids = [group.id for group in groups] - user = self.ResUsers.with_context(**{"no_reset_password": True}).create( + user = cls.ResUsers.with_context(**{"no_reset_password": True}).create( { "name": "Chicago Purchase User", "login": login, @@ -72,7 +73,8 @@ def _create_user(self, login, groups, company, operating_units): ) return user.id - def _create_purchase(self, user_id, line_products): + @classmethod + def _create_purchase(cls, user_id, line_products): """Create a purchase order. ``line_products`` is a list of tuple [(product, qty)] """ @@ -87,18 +89,19 @@ def _create_purchase(self, user_id, line_products): "date_planned": time.strftime(DEFAULT_SERVER_DATETIME_FORMAT), } lines.append((0, 0, line_values)) - purchase = self.PurchaseOrder.with_user(user_id).create( + purchase = cls.PurchaseOrder.with_user(user_id).create( { - "operating_unit_id": self.ou1.id, - "requesting_operating_unit_id": self.ou1.id, - "partner_id": self.partner1.id, + "operating_unit_id": cls.ou1.id, + "requesting_operating_unit_id": cls.ou1.id, + "partner_id": cls.partner1.id, "order_line": lines, - "company_id": self.company.id, + "company_id": cls.company.id, } ) return purchase - def _create_invoice(self, purchase, partner, account): + @classmethod + def _create_invoice(cls, purchase, partner, account): """Create a vendor invoice for the purchase order.""" invoice_vals = { "purchase_id": purchase.id, @@ -111,7 +114,7 @@ def _create_invoice(self, purchase, partner, account): "active_model": "purchase.order", } res = ( - self.env["account.move"] + cls.env["account.move"] .with_context(**purchase_context) .create(invoice_vals) ) diff --git a/purchase_operating_unit/views/account_move_view.xml b/purchase_operating_unit/views/account_move_view.xml index 028c677b79..ef275fe063 100644 --- a/purchase_operating_unit/views/account_move_view.xml +++ b/purchase_operating_unit/views/account_move_view.xml @@ -7,10 +7,9 @@ - [('id', 'in', purchase_ou_domain)] - - - + ['|',('operating_unit_id', '=', operating_unit_id),('operating_unit_id', '=', False)] diff --git a/purchase_operating_unit/views/purchase_order_view.xml b/purchase_operating_unit/views/purchase_order_view.xml index 13c2b00da5..9377ee3b85 100644 --- a/purchase_operating_unit/views/purchase_order_view.xml +++ b/purchase_operating_unit/views/purchase_order_view.xml @@ -22,10 +22,12 @@