2
0

[15.0][MIG] account_move_line_purchase_info: Migration to 15.0

This commit is contained in:
Joan Mateu Jordi 2021-11-24 10:22:19 +01:00 committed by Andrea Stirpe
parent 5649dd1511
commit a2370b31f9
4 changed files with 54 additions and 52 deletions

View File

@ -5,7 +5,7 @@
{ {
"name": "Account Move Line Purchase Info", "name": "Account Move Line Purchase Info",
"summary": "Introduces the purchase order line to the journal items", "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)", "author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools", "website": "https://github.com/OCA/account-financial-tools",
"category": "Generic", "category": "Generic",

View File

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

View File

@ -1,23 +1,7 @@
# Copyright 2019-2020 ForgeFlow S.L. # Copyright 2019-2020 ForgeFlow S.L.
# (https://www.forgeflow.com) # (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models
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)
class PurchaseOrderLine(models.Model): class PurchaseOrderLine(models.Model):

View File

@ -1,4 +1,4 @@
# Copyright 2019 ForgeFlow S.L. # Copyright 2021 ForgeFlow S.L.
# (https://www.forgeflow.com) # (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # 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): class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
def setUp(self): @classmethod
super(TestAccountMoveLinePurchaseInfo, self).setUp() def setUpClass(cls):
self.purchase_model = self.env["purchase.order"] super(TestAccountMoveLinePurchaseInfo, cls).setUpClass()
self.purchase_line_model = self.env["purchase.order.line"] cls.purchase_model = cls.env["purchase.order"]
self.product_model = self.env["product.product"] cls.purchase_line_model = cls.env["purchase.order.line"]
self.product_ctg_model = self.env["product.category"] cls.product_model = cls.env["product.product"]
self.acc_type_model = self.env["account.account.type"] cls.product_ctg_model = cls.env["product.category"]
self.account_model = self.env["account.account"] cls.acc_type_model = cls.env["account.account.type"]
self.am_model = self.env["account.move"] cls.account_model = cls.env["account.account"]
self.aml_model = self.env["account.move.line"] cls.am_model = cls.env["account.move"]
self.res_users_model = self.env["res.users"] 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") cls.partner1 = cls.env.ref("base.res_partner_1")
self.location_stock = self.env.ref("stock.stock_location_stock") cls.location_stock = cls.env.ref("stock.stock_location_stock")
self.company = self.env.ref("base.main_company") cls.company = cls.env.ref("base.main_company")
self.group_purchase_user = self.env.ref("purchase.group_purchase_user") cls.group_purchase_user = cls.env.ref("purchase.group_purchase_user")
self.group_account_invoice = self.env.ref("account.group_account_invoice") cls.group_account_invoice = cls.env.ref("account.group_account_invoice")
self.group_account_manager = self.env.ref("account.group_account_manager") cls.group_account_manager = cls.env.ref("account.group_account_manager")
# Create account for Goods Received Not Invoiced # 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" name = "Goods Received Not Invoiced"
code = "grni" 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 # 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" name = "Cost of Goods Sold"
code = "cogs" 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 # Create account for Inventory
acc_type = self._create_account_type("asset", "other") acc_type = cls._create_account_type(cls, "asset", "other")
name = "Inventory" name = "Inventory"
code = "inventory" code = "inventory"
self.account_inventory = self._create_account( cls.account_inventory = cls._create_account(
acc_type, name, code, self.company cls, acc_type, name, code, cls.company
) )
# Create Product # Create Product
self.product = self._create_product() cls.product = cls._create_product(cls)
# Create users # Create users
self.purchase_user = self._create_user( cls.purchase_user = cls._create_user(
cls,
"purchase_user", "purchase_user",
[self.group_purchase_user, self.group_account_invoice], [cls.group_purchase_user, cls.group_account_invoice],
self.company, cls.company,
) )
self.account_invoice = self._create_user( cls.account_invoice = cls._create_user(
"account_invoice", [self.group_account_invoice], self.company cls, "account_invoice", [cls.group_account_invoice], cls.company
) )
self.account_manager = self._create_user( cls.account_manager = cls._create_user(
"account_manager", [self.group_account_manager], self.company cls, "account_manager", [cls.group_account_manager], cls.company
) )
def _create_user(self, login, groups, company): def _create_user(self, login, groups, company):
@ -195,7 +197,7 @@ class TestAccountMoveLinePurchaseInfo(common.TransactionCase):
f.partner_id = purchase.partner_id f.partner_id = purchase.partner_id
f.purchase_id = purchase f.purchase_id = purchase
invoice = f.save() invoice = f.save()
invoice.post() invoice.action_post()
purchase.flush() purchase.flush()
for aml in invoice.invoice_line_ids: for aml in invoice.invoice_line_ids: