From a2370b31f92065de13714552bd9e408f390b4d1f Mon Sep 17 00:00:00 2001 From: Joan Mateu Jordi Date: Wed, 24 Nov 2021 10:22:19 +0100 Subject: [PATCH] [15.0][MIG] account_move_line_purchase_info: Migration to 15.0 --- .../__manifest__.py | 2 +- .../models/purchase_order.py | 16 +++++ .../models/purchase_order_line.py | 18 +---- .../test_account_move_line_purchase_info.py | 70 ++++++++++--------- 4 files changed, 54 insertions(+), 52 deletions(-) create mode 100644 account_move_line_purchase_info/models/purchase_order.py diff --git a/account_move_line_purchase_info/__manifest__.py b/account_move_line_purchase_info/__manifest__.py index f42cc3f7..b9faf844 100644 --- a/account_move_line_purchase_info/__manifest__.py +++ b/account_move_line_purchase_info/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Account Move Line Purchase Info", "summary": "Introduces the purchase order line to the journal items", - "version": "14.0.1.0.1", + "version": "15.0.1.0.0", "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", "category": "Generic", diff --git a/account_move_line_purchase_info/models/purchase_order.py b/account_move_line_purchase_info/models/purchase_order.py new file mode 100644 index 00000000..b0be2415 --- /dev/null +++ b/account_move_line_purchase_info/models/purchase_order.py @@ -0,0 +1,16 @@ +from odoo import api, models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + @api.depends("order_line.invoice_lines.move_id") + def _compute_invoice(self): + """Overwritten compute to avoid show all Journal Entries with + purchase_order_line as invoice_lines One2many would take them into account.""" + for order in self: + invoices = order.order_line.invoice_lines.move_id.filtered( + lambda m: m.is_invoice(include_receipts=True) + ) + order.invoice_ids = invoices + order.invoice_count = len(invoices) diff --git a/account_move_line_purchase_info/models/purchase_order_line.py b/account_move_line_purchase_info/models/purchase_order_line.py index d8109596..835259d2 100644 --- a/account_move_line_purchase_info/models/purchase_order_line.py +++ b/account_move_line_purchase_info/models/purchase_order_line.py @@ -1,23 +1,7 @@ # Copyright 2019-2020 ForgeFlow S.L. # (https://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - -from odoo import api, models - - -class PurchaseOrder(models.Model): - _inherit = "purchase.order" - - @api.depends("order_line.invoice_lines.move_id") - def _compute_invoice(self): - """Overwritten compute to avoid show all Journal Entries with - purchase_order_line as invoice_lines One2many would take them into account.""" - for order in self: - invoices = order.mapped("order_line.invoice_lines.move_id").filtered( - lambda m: m.is_invoice(include_receipts=True) - ) - order.invoice_ids = [(6, 0, invoices.ids)] - order.invoice_count = len(invoices) +from odoo import models class PurchaseOrderLine(models.Model): diff --git a/account_move_line_purchase_info/tests/test_account_move_line_purchase_info.py b/account_move_line_purchase_info/tests/test_account_move_line_purchase_info.py index 535eef90..de0b61a9 100644 --- a/account_move_line_purchase_info/tests/test_account_move_line_purchase_info.py +++ b/account_move_line_purchase_info/tests/test_account_move_line_purchase_info.py @@ -1,4 +1,4 @@ -# Copyright 2019 ForgeFlow S.L. +# Copyright 2021 ForgeFlow S.L. # (https://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). @@ -7,57 +7,59 @@ from odoo.tests import Form, common class TestAccountMoveLinePurchaseInfo(common.TransactionCase): - def setUp(self): - super(TestAccountMoveLinePurchaseInfo, self).setUp() - self.purchase_model = self.env["purchase.order"] - self.purchase_line_model = self.env["purchase.order.line"] - self.product_model = self.env["product.product"] - self.product_ctg_model = self.env["product.category"] - self.acc_type_model = self.env["account.account.type"] - self.account_model = self.env["account.account"] - self.am_model = self.env["account.move"] - self.aml_model = self.env["account.move.line"] - self.res_users_model = self.env["res.users"] + @classmethod + def setUpClass(cls): + super(TestAccountMoveLinePurchaseInfo, cls).setUpClass() + cls.purchase_model = cls.env["purchase.order"] + cls.purchase_line_model = cls.env["purchase.order.line"] + cls.product_model = cls.env["product.product"] + cls.product_ctg_model = cls.env["product.category"] + cls.acc_type_model = cls.env["account.account.type"] + cls.account_model = cls.env["account.account"] + cls.am_model = cls.env["account.move"] + cls.aml_model = cls.env["account.move.line"] + cls.res_users_model = cls.env["res.users"] - self.partner1 = self.env.ref("base.res_partner_1") - self.location_stock = self.env.ref("stock.stock_location_stock") - self.company = self.env.ref("base.main_company") - self.group_purchase_user = self.env.ref("purchase.group_purchase_user") - self.group_account_invoice = self.env.ref("account.group_account_invoice") - self.group_account_manager = self.env.ref("account.group_account_manager") + cls.partner1 = cls.env.ref("base.res_partner_1") + cls.location_stock = cls.env.ref("stock.stock_location_stock") + cls.company = cls.env.ref("base.main_company") + cls.group_purchase_user = cls.env.ref("purchase.group_purchase_user") + cls.group_account_invoice = cls.env.ref("account.group_account_invoice") + cls.group_account_manager = cls.env.ref("account.group_account_manager") # Create account for Goods Received Not Invoiced - acc_type = self._create_account_type("equity", "other") + acc_type = cls._create_account_type(cls, "equity", "other") name = "Goods Received Not Invoiced" code = "grni" - self.account_grni = self._create_account(acc_type, name, code, self.company) + cls.account_grni = cls._create_account(cls, acc_type, name, code, cls.company) # Create account for Cost of Goods Sold - acc_type = self._create_account_type("expense", "other") + acc_type = cls._create_account_type(cls, "expense", "other") name = "Cost of Goods Sold" code = "cogs" - self.account_cogs = self._create_account(acc_type, name, code, self.company) + cls.account_cogs = cls._create_account(cls, acc_type, name, code, cls.company) # Create account for Inventory - acc_type = self._create_account_type("asset", "other") + acc_type = cls._create_account_type(cls, "asset", "other") name = "Inventory" code = "inventory" - self.account_inventory = self._create_account( - acc_type, name, code, self.company + cls.account_inventory = cls._create_account( + cls, acc_type, name, code, cls.company ) # Create Product - self.product = self._create_product() + cls.product = cls._create_product(cls) # Create users - self.purchase_user = self._create_user( + cls.purchase_user = cls._create_user( + cls, "purchase_user", - [self.group_purchase_user, self.group_account_invoice], - self.company, + [cls.group_purchase_user, cls.group_account_invoice], + cls.company, ) - self.account_invoice = self._create_user( - "account_invoice", [self.group_account_invoice], self.company + cls.account_invoice = cls._create_user( + cls, "account_invoice", [cls.group_account_invoice], cls.company ) - self.account_manager = self._create_user( - "account_manager", [self.group_account_manager], self.company + cls.account_manager = cls._create_user( + cls, "account_manager", [cls.group_account_manager], cls.company ) def _create_user(self, login, groups, company): @@ -195,7 +197,7 @@ class TestAccountMoveLinePurchaseInfo(common.TransactionCase): f.partner_id = purchase.partner_id f.purchase_id = purchase invoice = f.save() - invoice.post() + invoice.action_post() purchase.flush() for aml in invoice.invoice_line_ids: