From 0c98de15faad7c419c099a549bb4898b9a54f6f4 Mon Sep 17 00:00:00 2001 From: Wolfgang Pichler Date: Tue, 25 Oct 2022 09:37:55 +0200 Subject: [PATCH] [MIG] account_payment_order: Migration to 16.0 --- account_payment_order/__manifest__.py | 3 +- .../migrations/14.0.1.3.0/pre-migration.py | 10 ------ account_payment_order/models/account_move.py | 3 +- .../models/account_move_line.py | 15 ++++---- .../models/account_payment.py | 32 ++++++----------- .../models/account_payment_line.py | 16 +++++---- .../models/account_payment_order.py | 36 ++++++++++--------- .../report/account_payment_order.xml | 28 ++++----------- .../tests/test_account_payment.py | 9 ----- .../tests/test_payment_order_outbound.py | 8 ++--- .../views/account_payment_line.xml | 3 +- .../wizard/account_payment_line_create.py | 12 +++++-- .../odoo/addons/account_payment_order | 1 + setup/account_payment_order/setup.py | 6 ++++ 14 files changed, 80 insertions(+), 102 deletions(-) delete mode 100644 account_payment_order/migrations/14.0.1.3.0/pre-migration.py create mode 120000 setup/account_payment_order/odoo/addons/account_payment_order create mode 100644 setup/account_payment_order/setup.py diff --git a/account_payment_order/__manifest__.py b/account_payment_order/__manifest__.py index 9e8e9f9cf..69252aa53 100644 --- a/account_payment_order/__manifest__.py +++ b/account_payment_order/__manifest__.py @@ -9,7 +9,7 @@ { "name": "Account Payment Order", - "version": "15.0.1.1.2", + "version": "16.0.1.0.0", "license": "AGPL-3", "author": "ACSONE SA/NV, " "Therp BV, " @@ -19,7 +19,6 @@ "website": "https://github.com/OCA/bank-payment", "development_status": "Mature", "category": "Banking addons", - "external_dependencies": {"python": ["lxml"]}, "depends": ["account_payment_partner", "base_iban"], # for manual_bank_tranfer "data": [ "views/account_payment_method.xml", diff --git a/account_payment_order/migrations/14.0.1.3.0/pre-migration.py b/account_payment_order/migrations/14.0.1.3.0/pre-migration.py deleted file mode 100644 index f5f7ace2c..000000000 --- a/account_payment_order/migrations/14.0.1.3.0/pre-migration.py +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright 2021 Akretion France (http://www.akretion.com/) -# @author: Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - - -def migrate(cr, version): - if not version: - return - - cr.execute("UPDATE account_payment_order SET state='uploaded' WHERE state='done'") diff --git a/account_payment_order/models/account_move.py b/account_payment_order/models/account_move.py index 0a04e895d..44c372c69 100644 --- a/account_payment_order/models/account_move.py +++ b/account_payment_order/models/account_move.py @@ -61,7 +61,8 @@ class AccountMove(models.Model): lambda x: ( not x.reconciled and x.payment_mode_id.payment_order_ok - and x.account_id.internal_type in ("receivable", "payable") + and x.account_id.account_type + in ("asset_receivable", "liability_payable") and not any( p_state in ("draft", "open", "generated") for p_state in x.payment_line_ids.mapped("state") diff --git a/account_payment_order/models/account_move_line.py b/account_payment_order/models/account_move_line.py index ec0759fdf..be249db16 100644 --- a/account_payment_order/models/account_move_line.py +++ b/account_payment_order/models/account_move_line.py @@ -32,7 +32,8 @@ class AccountMoveLine(models.Model): ml.move_id.move_type in ("in_invoice", "in_refund") and not ml.reconciled and ml.payment_mode_id.payment_order_ok - and ml.account_id.internal_type in ("receivable", "payable") + and ml.account_id.account_type + in ("asset_receivable", "liability_payable") and not any( p_state in ("draft", "open", "generated") for p_state in ml.payment_line_ids.mapped("state") @@ -64,11 +65,13 @@ class AccountMoveLine(models.Model): ) reference_moves |= self.move_id.reversal_move_id # Retrieve partial payments - e.g.: manual credit notes - for ( - _, - _, - payment_move_line, - ) in self.move_id._get_reconciled_invoices_partials(): + ( + invoice_partials, + exchange_diff_moves, + ) = self.move_id._get_reconciled_invoices_partials() + for (_, _, payment_move_line,) in ( + invoice_partials + exchange_diff_moves + ): payment_move = payment_move_line.move_id if payment_move not in reference_moves and ( payment_move.payment_reference or payment_move.ref diff --git a/account_payment_order/models/account_payment.py b/account_payment_order/models/account_payment.py index b10bfda63..ee3409e63 100644 --- a/account_payment_order/models/account_payment.py +++ b/account_payment_order/models/account_payment.py @@ -11,19 +11,20 @@ class AccountPayment(models.Model): payment_order_id = fields.Many2one(comodel_name="account.payment.order") payment_line_ids = fields.Many2many(comodel_name="account.payment.line") - def _get_default_journal(self): - res = super()._get_default_journal() - return res.filtered(lambda journal: not journal.inbound_payment_order_only) - @api.depends("payment_type", "journal_id") def _compute_payment_method_line_fields(self): res = super()._compute_payment_method_line_fields() for pay in self: - pay.available_payment_method_line_ids = ( - pay.journal_id._get_available_payment_method_lines( - pay.payment_type - ).filtered(lambda x: not x.payment_method_id.payment_order_only) - ) + if pay.payment_order_id: + pay.available_payment_method_line_ids = ( + pay.journal_id._get_available_payment_method_lines(pay.payment_type) + ) + else: + pay.available_payment_method_line_ids = ( + pay.journal_id._get_available_payment_method_lines( + pay.payment_type + ).filtered(lambda x: not x.payment_method_id.payment_order_only) + ) to_exclude = pay._get_payment_method_codes_to_exclude() if to_exclude: pay.available_payment_method_line_ids = ( @@ -31,17 +32,4 @@ class AccountPayment(models.Model): lambda x: x.code not in to_exclude ) ) - if ( - pay.payment_method_line_id.id - not in pay.available_payment_method_line_ids.ids - ): - # In some cases, we could be linked to a payment method - # line that has been unlinked from the journal. - # In such cases, we want to show it on the payment. - pay.hide_payment_method_line = False - else: - pay.hide_payment_method_line = ( - len(pay.available_payment_method_line_ids) == 1 - and pay.available_payment_method_line_ids.code == "manual" - ) return res diff --git a/account_payment_order/models/account_payment_line.py b/account_payment_order/models/account_payment_line.py index 44c61ea03..582f786d7 100644 --- a/account_payment_order/models/account_payment_line.py +++ b/account_payment_order/models/account_payment_line.py @@ -91,13 +91,15 @@ class AccountPaymentLine(models.Model): ) ] - @api.model - def create(self, vals): - if vals.get("name", "New") == "New": - vals["name"] = ( - self.env["ir.sequence"].next_by_code("account.payment.line") or "New" - ) - return super(AccountPaymentLine, self).create(vals) + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if vals.get("name", "New") == "New": + vals["name"] = ( + self.env["ir.sequence"].next_by_code("account.payment.line") + or "New" + ) + return super().create(vals_list) @api.depends("amount_currency", "currency_id", "company_currency_id", "date") def _compute_amount_company_currency(self): diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py index 7bd0fe4f8..341acbe3e 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -221,22 +221,24 @@ class AccountPaymentOrder(models.Model): for order in self: order.move_count = mapped_data.get(order.id, 0) - @api.model - def create(self, vals): - if vals.get("name", "New") == "New": - vals["name"] = ( - self.env["ir.sequence"].next_by_code("account.payment.order") or "New" - ) - if vals.get("payment_mode_id"): - payment_mode = self.env["account.payment.mode"].browse( - vals["payment_mode_id"] - ) - vals["payment_type"] = payment_mode.payment_type - if payment_mode.bank_account_link == "fixed": - vals["journal_id"] = payment_mode.fixed_journal_id.id - if not vals.get("date_prefered") and payment_mode.default_date_prefered: - vals["date_prefered"] = payment_mode.default_date_prefered - return super(AccountPaymentOrder, self).create(vals) + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if vals.get("name", "New") == "New": + vals["name"] = ( + self.env["ir.sequence"].next_by_code("account.payment.order") + or "New" + ) + if vals.get("payment_mode_id"): + payment_mode = self.env["account.payment.mode"].browse( + vals["payment_mode_id"] + ) + vals["payment_type"] = payment_mode.payment_type + if payment_mode.bank_account_link == "fixed": + vals["journal_id"] = payment_mode.fixed_journal_id.id + if not vals.get("date_prefered") and payment_mode.default_date_prefered: + vals["date_prefered"] = payment_mode.default_date_prefered + return super(AccountPaymentOrder, self).create(vals_list) @api.onchange("payment_mode_id") def payment_mode_id_change(self): @@ -343,7 +345,7 @@ class AccountPaymentOrder(models.Model): "paylines": payline, "total": payline.amount_currency, } - order.recompute() + order.env.flush_all() # Create account payments payment_vals = [] for paydict in list(group_paylines.values()): diff --git a/account_payment_order/report/account_payment_order.xml b/account_payment_order/report/account_payment_order.xml index bd77e9c64..c80693b0a 100644 --- a/account_payment_order/report/account_payment_order.xml +++ b/account_payment_order/report/account_payment_order.xml @@ -12,27 +12,13 @@
- - - - - - - +
+
+
+
+
+
+
diff --git a/account_payment_order/tests/test_account_payment.py b/account_payment_order/tests/test_account_payment.py index feee07439..2c95da0a7 100644 --- a/account_payment_order/tests/test_account_payment.py +++ b/account_payment_order/tests/test_account_payment.py @@ -105,9 +105,6 @@ class TestAccountPayment(AccountTestInvoicingCommon): "company_id": self.company.id, } ) - # check journals - journals = new_account_payment._get_default_journal() - self.assertIn(self.bank_journal, journals) # check payment methods payment_methods = ( new_account_payment.available_payment_method_line_ids.filtered( @@ -120,9 +117,6 @@ class TestAccountPayment(AccountTestInvoicingCommon): self.assertIn(self.inbound_payment_method_02.id, payment_methods) # Set one payment method of the bank journal 'payment order only' self.inbound_payment_method_01.payment_order_only = True - # check journals - journals = new_account_payment._get_default_journal() - self.assertIn(self.bank_journal, journals) # check payment methods new_account_payment2 = self.account_payment_model.with_context( default_company_id=self.company.id @@ -143,9 +137,6 @@ class TestAccountPayment(AccountTestInvoicingCommon): for p in self.bank_journal.inbound_payment_method_line_ids.payment_method_id: p.payment_order_only = True self.assertTrue(self.bank_journal.inbound_payment_order_only) - # check journals - journals = new_account_payment._get_default_journal() - self.assertNotIn(self.bank_journal, journals) # check payment methods new_account_payment3 = self.account_payment_model.with_context( default_company_id=self.company.id diff --git a/account_payment_order/tests/test_payment_order_outbound.py b/account_payment_order/tests/test_payment_order_outbound.py index 833490739..5ad16c0b5 100644 --- a/account_payment_order/tests/test_payment_order_outbound.py +++ b/account_payment_order/tests/test_payment_order_outbound.py @@ -28,7 +28,7 @@ class TestPaymentOrderOutboundBase(AccountTestInvoicingCommon): { "name": "Test account", "code": "TEST1", - "user_type_id": cls.env.ref("account.data_account_type_expenses").id, + "account_type": "expense", } ) cls.mode = cls.env["account.payment.mode"].create( @@ -361,10 +361,10 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase): # The user add the outstanding payment to the invoice invoice_line = self.invoice.line_ids.filtered( - lambda line: line.account_internal_type == "payable" + lambda line: line.account_type == "liability_payable" ) refund_line = self.refund.line_ids.filtered( - lambda line: line.account_internal_type == "payable" + lambda line: line.account_type == "liability_payable" ) (invoice_line | refund_line).reconcile() @@ -399,7 +399,7 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase): self.refund.action_post() (self.invoice.line_ids + self.refund.line_ids).filtered( - lambda line: line.account_internal_type == "payable" + lambda line: line.account_type == "liability_payable" ).reconcile() self.env["account.invoice.payment.line.multi"].with_context( diff --git a/account_payment_order/views/account_payment_line.xml b/account_payment_order/views/account_payment_line.xml index 1c2c72a06..bac69aff5 100644 --- a/account_payment_order/views/account_payment_line.xml +++ b/account_payment_order/views/account_payment_line.xml @@ -7,6 +7,7 @@
+ diff --git a/account_payment_order/wizard/account_payment_line_create.py b/account_payment_order/wizard/account_payment_line_create.py index 4feb8eeb1..0759c5ef6 100644 --- a/account_payment_order/wizard/account_payment_line_create.py +++ b/account_payment_order/wizard/account_payment_line_create.py @@ -119,12 +119,20 @@ class AccountPaymentLineCreate(models.TransientModel): # will not be refunded with a payment. domain += [ ("credit", ">", 0), - ("account_id.internal_type", "in", ["payable", "receivable"]), + ( + "account_id.account_type", + "in", + ["liability_payable", "asset_receivable"], + ), ] elif self.order_id.payment_type == "inbound": domain += [ ("debit", ">", 0), - ("account_id.internal_type", "in", ["receivable", "payable"]), + ( + "account_id.account_type", + "in", + ["asset_receivable", "liability_payable"], + ), ] # Exclude lines that are already in a non-cancelled # and non-uploaded payment order; lines that are in a diff --git a/setup/account_payment_order/odoo/addons/account_payment_order b/setup/account_payment_order/odoo/addons/account_payment_order new file mode 120000 index 000000000..06957e99f --- /dev/null +++ b/setup/account_payment_order/odoo/addons/account_payment_order @@ -0,0 +1 @@ +../../../../account_payment_order \ No newline at end of file diff --git a/setup/account_payment_order/setup.py b/setup/account_payment_order/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_payment_order/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)