From 8f58983ea04f0d3fbc095a4f908c0753cb795500 Mon Sep 17 00:00:00 2001 From: Flectra Community Bot Date: Sun, 19 Sep 2021 02:09:57 +0000 Subject: [PATCH] Automatic Update form OCA2FC Migrator --- README.md | 4 +- account_payment_order/__manifest__.py | 2 +- .../tests/test_account_payment.py | 51 +++++++++---- .../tests/test_payment_order_inbound.py | 68 +++++++++--------- .../tests/test_payment_order_outbound.py | 71 +++++++++++-------- account_payment_partner/__manifest__.py | 2 +- .../models/account_move.py | 4 +- .../tests/test_account_payment_partner.py | 18 ++++- 8 files changed, 137 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index 4b48159..684d3a9 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,11 @@ addon | version | summary [account_payment_sale](account_payment_sale/) | 2.0.1.0.0| Adds payment mode on sale orders [account_banking_pain_base](account_banking_pain_base/) | 2.0.1.0.0| Base module for PAIN file generation [account_banking_mandate](account_banking_mandate/) | 2.0.1.1.0| Banking mandates -[account_payment_order](account_payment_order/) | 2.0.1.2.3| Account Payment Order +[account_payment_order](account_payment_order/) | 2.0.1.2.4| Account Payment Order [account_payment_purchase_stock](account_payment_purchase_stock/) | 2.0.1.0.0| Integrate Account Payment Purchase with Stock [account_banking_sepa_credit_transfer](account_banking_sepa_credit_transfer/) | 2.0.1.0.0| Create SEPA XML files for Credit Transfers [account_payment_mode](account_payment_mode/) | 2.0.1.0.1| Account Payment Mode -[account_payment_partner](account_payment_partner/) | 2.0.1.3.0| Adds payment mode on partners and invoices +[account_payment_partner](account_payment_partner/) | 2.0.1.3.1| Adds payment mode on partners and invoices [account_payment_order_return](account_payment_order_return/) | 2.0.1.0.1| Account Payment Order Return diff --git a/account_payment_order/__manifest__.py b/account_payment_order/__manifest__.py index ed41889..125de8c 100644 --- a/account_payment_order/__manifest__.py +++ b/account_payment_order/__manifest__.py @@ -8,7 +8,7 @@ { "name": "Account Payment Order", - "version": "2.0.1.2.3", + "version": "2.0.1.2.4", "license": "AGPL-3", "author": "ACSONE SA/NV, " "Therp BV, " diff --git a/account_payment_order/tests/test_account_payment.py b/account_payment_order/tests/test_account_payment.py index 0f18a0c..62e9f90 100644 --- a/account_payment_order/tests/test_account_payment.py +++ b/account_payment_order/tests/test_account_payment.py @@ -1,13 +1,16 @@ # Copyright 2019 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from flectra.tests.common import SavepointCase + +from flectra.addons.account.tests.common import AccountTestInvoicingCommon -class TestAccountPayment(SavepointCase): +class TestAccountPayment(AccountTestInvoicingCommon): @classmethod - def setUpClass(cls): - super(TestAccountPayment, cls).setUpClass() + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + cls.company = cls.company_data["company"] + cls.env.user.company_ids += cls.company # MODELS cls.account_payment_model = cls.env["account.payment"] @@ -16,17 +19,28 @@ class TestAccountPayment(SavepointCase): # INSTANCES # Payment methods - ( - cls.inbound_payment_method_01, - cls.inbound_payment_method_02, - ) = cls.payment_method_model.search([("payment_type", "=", "inbound")], limit=2) - cls.outbound_payment_method_01 = cls.payment_method_model.search( - [("payment_type", "=", "outbound")], limit=1 + cls.inbound_payment_method_01 = cls.payment_method_model.create( + { + "name": "inbound", + "code": "IN", + "payment_type": "inbound", + } + ) + cls.inbound_payment_method_02 = cls.inbound_payment_method_01.copy( + { + "name": "inbound 2", + "code": "IN2", + } + ) + cls.outbound_payment_method_01 = cls.payment_method_model.create( + { + "name": "outbound", + "code": "OUT", + "payment_type": "outbound", + } ) # Journals - cls.bank_journal = cls.account_journal_model.search( - [("type", "=", "bank")], limit=1 - ) + cls.bank_journal = cls.company_data["default_journal_bank"] cls.bank_journal.inbound_payment_method_ids = [ ( 6, @@ -62,8 +76,15 @@ class TestAccountPayment(SavepointCase): self.assertFalse(self.inbound_payment_method_01.payment_order_only) self.assertFalse(self.inbound_payment_method_02.payment_order_only) self.assertFalse(self.bank_journal.inbound_payment_order_only) - new_account_payment = self.account_payment_model.new( - {"journal_id": self.bank_journal.id, "payment_type": "inbound", "amount": 1} + new_account_payment = self.account_payment_model.with_context( + default_company_id=self.company.id + ).new( + { + "journal_id": self.bank_journal.id, + "payment_type": "inbound", + "amount": 1, + "company_id": self.company.id, + } ) # check journals journals = new_account_payment._get_default_journal() diff --git a/account_payment_order/tests/test_payment_order_inbound.py b/account_payment_order/tests/test_payment_order_inbound.py index 8b94449..1e5f34d 100644 --- a/account_payment_order/tests/test_payment_order_inbound.py +++ b/account_payment_order/tests/test_payment_order_inbound.py @@ -6,59 +6,64 @@ from datetime import date, timedelta from flectra.exceptions import UserError, ValidationError -from flectra.tests.common import Form, SavepointCase +from flectra.tests.common import Form + +from flectra.addons.account.tests.common import AccountTestInvoicingCommon -class TestPaymentOrderInboundBase(SavepointCase): +class TestPaymentOrderInboundBase(AccountTestInvoicingCommon): @classmethod - def setUpClass(cls): - self = cls - super().setUpClass() - self.env.user.company_id = self.env.ref("base.main_company").id - self.inbound_mode = self.env.ref( - "account_payment_mode.payment_mode_inbound_dd1" - ) - self.invoice_line_account = self.env["account.account"].create( + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + cls.company = cls.company_data["company"] + cls.env.user.company_id = cls.company.id + cls.partner = cls.env["res.partner"].create( { - "name": "Test account", - "code": "TEST1", - "user_type_id": self.env.ref("account.data_account_type_revenue").id, + "name": "Test Partner", } ) - self.journal = self.env["account.journal"].search( - [("type", "=", "bank"), ("company_id", "=", self.env.user.company_id.id)], - limit=1, + cls.inbound_mode = cls.env["account.payment.mode"].create( + { + "name": "Test Direct Debit of customers", + "bank_account_link": "variable", + "payment_method_id": cls.env.ref( + "account.account_payment_method_manual_in" + ).id, + "company_id": cls.company.id, + } ) - self.inbound_mode.variable_journal_ids = self.journal + cls.invoice_line_account = cls.company_data["default_account_revenue"] + cls.journal = cls.company_data["default_journal_bank"] + cls.inbound_mode.variable_journal_ids = cls.journal # Make sure no others orders are present - self.domain = [ + cls.domain = [ ("state", "=", "draft"), ("payment_type", "=", "inbound"), - ("company_id", "=", self.env.user.company_id.id), + ("company_id", "=", cls.env.user.company_id.id), ] - self.payment_order_obj = self.env["account.payment.order"] - self.payment_order_obj.search(self.domain).unlink() + cls.payment_order_obj = cls.env["account.payment.order"] + cls.payment_order_obj.search(cls.domain).unlink() # Create payment order - self.inbound_order = self.env["account.payment.order"].create( + cls.inbound_order = cls.env["account.payment.order"].create( { "payment_type": "inbound", - "payment_mode_id": self.inbound_mode.id, - "journal_id": self.journal.id, + "payment_mode_id": cls.inbound_mode.id, + "journal_id": cls.journal.id, } ) # Open invoice - self.invoice = self._create_customer_invoice(self) - self.invoice.action_post() + cls.invoice = cls._create_customer_invoice(cls) + cls.invoice.action_post() # Add to payment order using the wizard - self.env["account.invoice.payment.line.multi"].with_context( - active_model="account.move", active_ids=self.invoice.ids + cls.env["account.invoice.payment.line.multi"].with_context( + active_model="account.move", active_ids=cls.invoice.ids ).create({}).run() def _create_customer_invoice(self): with Form( self.env["account.move"].with_context(default_move_type="out_invoice") ) as invoice_form: - invoice_form.partner_id = self.env.ref("base.res_partner_4") + invoice_form.partner_id = self.partner with invoice_form.invoice_line_ids.new() as invoice_line_form: invoice_line_form.product_id = self.env.ref("product.product_product_4") invoice_line_form.name = "product that cost 100" @@ -87,11 +92,8 @@ class TestPaymentOrderInbound(TestPaymentOrderInboundBase): def test_creation(self): payment_order = self.inbound_order self.assertEqual(len(payment_order.ids), 1) - bank_journal = self.env["account.journal"].search( - [("type", "=", "bank")], limit=1 - ) - payment_order.write({"journal_id": bank_journal.id}) + payment_order.write({"journal_id": self.journal.id}) self.assertEqual(len(payment_order.payment_line_ids), 1) self.assertEqual(len(payment_order.bank_line_ids), 0) diff --git a/account_payment_order/tests/test_payment_order_outbound.py b/account_payment_order/tests/test_payment_order_outbound.py index 44d5294..f7c7875 100644 --- a/account_payment_order/tests/test_payment_order_outbound.py +++ b/account_payment_order/tests/test_payment_order_outbound.py @@ -6,49 +6,65 @@ from datetime import date, datetime, timedelta from flectra import fields from flectra.exceptions import UserError, ValidationError -from flectra.tests.common import TransactionCase + +from flectra.addons.account.tests.common import AccountTestInvoicingCommon -class TestPaymentOrderOutbound(TransactionCase): - def setUp(self): - super(TestPaymentOrderOutbound, self).setUp() - self.env.user.company_id = self.env.ref("base.main_company").id - self.journal = self.env["account.journal"].search( - [("type", "=", "bank")], limit=1 +class TestPaymentOrderOutbound(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + cls.company = cls.company_data["company"] + cls.env.user.company_id = cls.company.id + cls.partner = cls.env["res.partner"].create( + { + "name": "Test Partner", + } ) - self.invoice_line_account = self.env["account.account"].create( + cls.invoice_line_account = cls.env["account.account"].create( { "name": "Test account", "code": "TEST1", - "user_type_id": self.env.ref("account.data_account_type_expenses").id, + "user_type_id": cls.env.ref("account.data_account_type_expenses").id, } ) - self.invoice = self._create_supplier_invoice() - self.invoice_02 = self._create_supplier_invoice() - self.mode = self.env.ref("account_payment_mode.payment_mode_outbound_ct1") - self.creation_mode = self.env.ref( - "account_payment_mode.payment_mode_outbound_dd1" + cls.mode = cls.env["account.payment.mode"].create( + { + "name": "Test Credit Transfer to Suppliers", + "company_id": cls.company.id, + "bank_account_link": "variable", + "payment_method_id": cls.env.ref( + "account.account_payment_method_manual_out" + ).id, + } ) - self.bank_journal = self.env["account.journal"].search( - [("type", "=", "bank"), ("company_id", "=", self.env.user.company_id.id)], - limit=1, + cls.creation_mode = cls.env["account.payment.mode"].create( + { + "name": "Test Direct Debit of suppliers from Société Générale", + "company_id": cls.company.id, + "bank_account_link": "variable", + "payment_method_id": cls.env.ref( + "account.account_payment_method_manual_out" + ).id, + } ) + cls.invoice = cls._create_supplier_invoice(cls) + cls.invoice_02 = cls._create_supplier_invoice(cls) + cls.bank_journal = cls.company_data["default_journal_bank"] # Make sure no other payment orders are in the DB - self.domain = [ + cls.domain = [ ("state", "=", "draft"), ("payment_type", "=", "outbound"), - ("company_id", "=", self.env.user.company_id.id), + ("company_id", "=", cls.env.user.company_id.id), ] - self.env["account.payment.order"].search(self.domain).unlink() + cls.env["account.payment.order"].search(cls.domain).unlink() def _create_supplier_invoice(self): invoice = self.env["account.move"].create( { - "partner_id": self.env.ref("base.res_partner_4").id, + "partner_id": self.partner.id, "move_type": "in_invoice", - "payment_mode_id": self.env.ref( - "account_payment_mode.payment_mode_outbound_ct1" - ).id, + "payment_mode_id": self.mode.id, "invoice_date": fields.Date.today(), "invoice_line_ids": [ ( @@ -154,11 +170,8 @@ class TestPaymentOrderOutbound(TransactionCase): payment_order = self.env["account.payment.order"].search(self.domain) self.assertEqual(len(payment_order), 1) - bank_journal = self.env["account.journal"].search( - [("type", "=", "bank")], limit=1 - ) - payment_order.write({"journal_id": bank_journal.id}) + payment_order.write({"journal_id": self.bank_journal.id}) self.assertEqual(len(payment_order.payment_line_ids), 1) self.assertEqual(len(payment_order.bank_line_ids), 0) @@ -191,7 +204,7 @@ class TestPaymentOrderOutbound(TransactionCase): { "payment_type": "outbound", "payment_mode_id": self.mode.id, - "journal_id": self.journal.id, + "journal_id": self.bank_journal.id, } ) with self.assertRaises(ValidationError): diff --git a/account_payment_partner/__manifest__.py b/account_payment_partner/__manifest__.py index 6e1ff77..1af64cb 100644 --- a/account_payment_partner/__manifest__.py +++ b/account_payment_partner/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Account Payment Partner", - "version": "2.0.1.3.0", + "version": "2.0.1.3.1", "category": "Banking addons", "license": "AGPL-3", "summary": "Adds payment mode on partners and invoices", diff --git a/account_payment_partner/models/account_move.py b/account_payment_partner/models/account_move.py index 5ab8e8f..c989844 100644 --- a/account_payment_partner/models/account_move.py +++ b/account_payment_partner/models/account_move.py @@ -56,7 +56,9 @@ class AccountMove(models.Model): @api.depends("partner_id", "company_id") def _compute_payment_mode(self): for move in self: - move.payment_mode_id = False + move.payment_mode_id = move.payment_mode_id + if move.company_id and move.payment_mode_id.company_id != move.company_id: + move.payment_mode_id = False if move.partner_id: partner = move.with_company(move.company_id.id).partner_id if move.move_type == "in_invoice": diff --git a/account_payment_partner/tests/test_account_payment_partner.py b/account_payment_partner/tests/test_account_payment_partner.py index 7767a5a..dcb7211 100644 --- a/account_payment_partner/tests/test_account_payment_partner.py +++ b/account_payment_partner/tests/test_account_payment_partner.py @@ -282,7 +282,7 @@ class TestAccountPaymentPartner(SavepointCase): self.assertFalse(invoice.partner_bank_id) invoice.partner_id = False - self.assertEqual(invoice.payment_mode_id, self.payment_mode_model) + self.assertEqual(invoice.payment_mode_id, self.supplier_payment_mode_c2) self.assertEqual(invoice.partner_bank_id, self.partner_bank_model) def test_invoice_create_in_invoice(self): @@ -550,3 +550,19 @@ class TestAccountPaymentPartner(SavepointCase): self.assertEqual( out_invoice.partner_bank_filter_type_domain, out_invoice.bank_partner_id ) + + def test_account_move_payment_mode_id_default(self): + payment_mode = self.env.ref("account_payment_mode.payment_mode_inbound_dd1") + field = self.env["ir.model.fields"].search( + [ + ("model_id.model", "=", self.move_model._name), + ("name", "=", "payment_mode_id"), + ] + ) + move_form = Form(self.move_model.with_context(default_type="out_invoice")) + self.assertFalse(move_form.payment_mode_id) + self.env["ir.default"].create( + {"field_id": field.id, "json_value": payment_mode.id} + ) + move_form = Form(self.move_model.with_context(default_type="out_invoice")) + self.assertEqual(move_form.payment_mode_id, payment_mode)