From 7b81867873978f7070a08fd7b0bda762409f6846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florent=20Cayr=C3=A9?= Date: Mon, 7 Oct 2024 12:02:12 +0200 Subject: [PATCH] [MIG] account_invoice_merge_attachment: Migration to 16.0 (from 12.0-mig-account_invoice_merge_attachment) --- .../__manifest__.py | 3 +- .../models/__init__.py | 2 +- .../{account_invoice.py => account_move.py} | 11 ++-- .../test_account_invoice_merge_attachment.py | 57 +++++++------------ .../wizards/invoice_merge.py | 1 - 5 files changed, 27 insertions(+), 47 deletions(-) rename account_invoice_merge_attachment/models/{account_invoice.py => account_move.py} (77%) diff --git a/account_invoice_merge_attachment/__manifest__.py b/account_invoice_merge_attachment/__manifest__.py index 46f9d86b25d..e559e2ee982 100644 --- a/account_invoice_merge_attachment/__manifest__.py +++ b/account_invoice_merge_attachment/__manifest__.py @@ -5,13 +5,12 @@ "name": "Account Invoice Merge Attachment", "summary": """ Consider attachment during invoice merge process""", - "version": "12.0.1.0.0", + "version": "16.0.1.0.0", "license": "AGPL-3", "author": "ACSONE SA/NV, Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-invoicing", "depends": [ "account_invoice_merge", - "document", ], "data": [ "wizards/invoice_merge.xml", diff --git a/account_invoice_merge_attachment/models/__init__.py b/account_invoice_merge_attachment/models/__init__.py index 8e072db8f3e..9c0a4213854 100644 --- a/account_invoice_merge_attachment/models/__init__.py +++ b/account_invoice_merge_attachment/models/__init__.py @@ -1 +1 @@ -from . import account_invoice +from . import account_move diff --git a/account_invoice_merge_attachment/models/account_invoice.py b/account_invoice_merge_attachment/models/account_move.py similarity index 77% rename from account_invoice_merge_attachment/models/account_invoice.py rename to account_invoice_merge_attachment/models/account_move.py index ad7eb58301a..24fb74bcd57 100644 --- a/account_invoice_merge_attachment/models/account_invoice.py +++ b/account_invoice_merge_attachment/models/account_move.py @@ -4,13 +4,14 @@ from odoo import models -class AccountInvoice(models.Model): +class AccountMove(models.Model): - _inherit = "account.invoice" + _inherit = "account.move" - @api.multi - def do_merge(self, keep_references=True, date_invoice=False): - invoices_info = super(AccountInvoice, self).do_merge( + def do_merge( + self, keep_references=True, date_invoice=False, remove_empty_invoice_lines=True + ): + invoices_info = super().do_merge( keep_references=keep_references, date_invoice=date_invoice ) diff --git a/account_invoice_merge_attachment/tests/test_account_invoice_merge_attachment.py b/account_invoice_merge_attachment/tests/test_account_invoice_merge_attachment.py index b4234871c41..19bb88afd3a 100644 --- a/account_invoice_merge_attachment/tests/test_account_invoice_merge_attachment.py +++ b/account_invoice_merge_attachment/tests/test_account_invoice_merge_attachment.py @@ -1,42 +1,12 @@ # Copyright 2016-2017 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests.common import TransactionCase +from odoo import fields +from odoo.addons.account.tests.common import AccountTestInvoicingCommon -class TestAccountInvoiceMergeAttachment(TransactionCase): - def setUp(self): - super(TestAccountInvoiceMergeAttachment, self).setUp() - self.AttachmentObj = self.env["ir.attachment"] - self.InvoiceObj = self.env["account.invoice"] - - self.partner = self.env.ref("base.main_partner") - self.product = self.env.ref("product.product_product_8") - self.product_account = ( - self.product.property_account_income_id - or self.product.categ_id.property_account_income_categ_id - ) - - def create_invoice(self): - return self.InvoiceObj.create( - { - "partner_id": self.partner.id, - "name": "Test", - "invoice_line_ids": [ - ( - 0, - 0, - { - "product_id": self.product.id, - "name": self.product.name, - "account_id": self.product_account.id, - "quantity": 1, - "price_unit": 1, - }, - ) - ], - } - ) +@tagged("post_install", "-at_install") +class TestAccountInvoiceMergeAttachment(AccountTestInvoicingCommon): def create_invoice_attachment(self, invoice): return self.AttachmentObj.create( @@ -44,16 +14,27 @@ def create_invoice_attachment(self, invoice): "name": "Attach", "datas_fname": "Attach", "datas": "bWlncmF0aW9uIHRlc3Q=", - "res_model": "account.invoice", + "res_model": invoice._name, "res_id": invoice.id, } ) def test_merge_invoice_attachments(self): - invoice1 = self.create_invoice() + today = fields.Date.today() + invoice1 = self.init_invoice( + "out_invoice", + partner=self.partner_a, + invoice_date=today, + products=self.product_a, + ) self.create_invoice_attachment(invoice1) - invoice2 = self.create_invoice() + invoice2 = self.init_invoice( + "out_invoice", + partner=self.partner_a, + invoice_date=today, + products=self.product_a, + ) self.create_invoice_attachment(invoice2) self.create_invoice_attachment(invoice2) @@ -63,7 +44,7 @@ def test_merge_invoice_attachments(self): attach = self.AttachmentObj.search( [ ("res_id", "in", list(invoices_info.keys())), - ("res_model", "=", "account.invoice"), + ("res_model", "=", invoices._name), ] ) self.assertEqual( diff --git a/account_invoice_merge_attachment/wizards/invoice_merge.py b/account_invoice_merge_attachment/wizards/invoice_merge.py index 227f56084e5..88954fdd433 100644 --- a/account_invoice_merge_attachment/wizards/invoice_merge.py +++ b/account_invoice_merge_attachment/wizards/invoice_merge.py @@ -10,7 +10,6 @@ class InvoiceMerge(models.TransientModel): link_attachment = fields.Boolean(string="Link attachments", default=True) - @api.multi def merge_invoices(self): self.ensure_one() return super(