From 3927e93f7f0bce6fcce1ffa6f6372403b40d3b28 Mon Sep 17 00:00:00 2001 From: Saran440 Date: Fri, 22 Nov 2024 15:27:29 +0700 Subject: [PATCH] [MIG] account_payment_multi_deduction: Migration to 18.0 --- .../__manifest__.py | 2 +- .../models/account_payment.py | 4 +- .../tests/test_payment_multi_deduction.py | 5 +- .../wizard/account_payment_register.py | 22 ++++++--- .../wizard/account_payment_register_views.xml | 49 +++++++++---------- 5 files changed, 44 insertions(+), 38 deletions(-) diff --git a/account_payment_multi_deduction/__manifest__.py b/account_payment_multi_deduction/__manifest__.py index a23045303e82..4149821b328e 100644 --- a/account_payment_multi_deduction/__manifest__.py +++ b/account_payment_multi_deduction/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Payment Register with Multiple Deduction", - "version": "16.0.1.0.0", + "version": "18.0.1.0.0", "author": "Ecosoft, Odoo Community Association (OCA)", "license": "AGPL-3", "website": "https://github.com/OCA/account-payment", diff --git a/account_payment_multi_deduction/models/account_payment.py b/account_payment_multi_deduction/models/account_payment.py index 2c8a2e01422c..9c5500896874 100644 --- a/account_payment_multi_deduction/models/account_payment.py +++ b/account_payment_multi_deduction/models/account_payment.py @@ -27,7 +27,7 @@ def _update_vals_writeoff( line_vals[update_key] = write_off_line_vals[0][update_key] break - def _prepare_move_line_default_vals(self, write_off_line_vals=None): + def _prepare_move_line_default_vals(self, write_off_line_vals=None, force_balance=None): """Split amount to multi payment deduction Concept: * Process by payment difference 'Mark as fully paid' and keep value is paid @@ -35,7 +35,7 @@ def _prepare_move_line_default_vals(self, write_off_line_vals=None): * Combine all process and return list """ self.ensure_one() - line_vals_list = super()._prepare_move_line_default_vals(write_off_line_vals) + line_vals_list = super()._prepare_move_line_default_vals(write_off_line_vals, force_balance) # payment difference if not self.is_multi_deduction and write_off_line_vals: # update writeoff when edit value in payment diff --git a/account_payment_multi_deduction/tests/test_payment_multi_deduction.py b/account_payment_multi_deduction/tests/test_payment_multi_deduction.py index 32203bc653c8..03c463063751 100644 --- a/account_payment_multi_deduction/tests/test_payment_multi_deduction.py +++ b/account_payment_multi_deduction/tests/test_payment_multi_deduction.py @@ -3,7 +3,8 @@ from odoo import Command, fields from odoo.exceptions import UserError -from odoo.tests.common import Form, TransactionCase +from odoo.tests.common import TransactionCase +from odoo.tests import Form class TestPaymentMultiDeduction(TransactionCase): @@ -20,14 +21,12 @@ def setUpClass(cls): cls.account_revenue = cls.env["account.account"].search( [ ("account_type", "=", "income"), - ("company_id", "=", cls.env.company.id), ], limit=1, ) cls.account_expense = cls.env["account.account"].search( [ ("account_type", "=", "expense"), - ("company_id", "=", cls.env.company.id), ], limit=1, ) diff --git a/account_payment_multi_deduction/wizard/account_payment_register.py b/account_payment_multi_deduction/wizard/account_payment_register.py index 4aad63d540c7..fecaefa78843 100644 --- a/account_payment_multi_deduction/wizard/account_payment_register.py +++ b/account_payment_multi_deduction/wizard/account_payment_register.py @@ -28,8 +28,9 @@ class AccountPaymentRegister(models.TransientModel): ) deduct_analytic_distribution = fields.Json() - def _update_vals_deduction(self, moves): - move_lines = moves.mapped("line_ids") + def _update_vals_deduction(self, move_lines): + """For case `Mark as fully paid`, + Hook this method to update field wizard write-off from move lines""" analytic = {} [ analytic.update(item) @@ -38,8 +39,9 @@ def _update_vals_deduction(self, moves): ] self.analytic_distribution = analytic - def _update_vals_multi_deduction(self, moves): - move_lines = moves.mapped("line_ids") + def _update_vals_multi_deduction(self, move_lines): + """For case `Mark invoice as fully paid (multi deduct)`, + Hook this method to update field wizard deduct from move lines""" analytic = {} [ analytic.update(item) @@ -51,11 +53,17 @@ def _update_vals_multi_deduction(self, moves): @api.onchange("payment_difference", "payment_difference_handling") def _onchange_default_deduction(self): active_ids = self.env.context.get("active_ids", []) - moves = self.env["account.move"].browse(active_ids) + move_lines = self.env["account.move.line"] + model = self.env.context.get("active_model", False) + if model == "account.move.line": + move_lines = move_lines.browse(active_ids) + elif model == "account.move": + move_lines = self.env["account.move"].browse(active_ids).line_ids + if self.payment_difference_handling == "reconcile": - self._update_vals_deduction(moves) + self._update_vals_deduction(move_lines) if self.payment_difference_handling == "reconcile_multi_deduct": - self._update_vals_multi_deduction(moves) + self._update_vals_multi_deduction(move_lines) @api.constrains("deduction_ids", "payment_difference_handling") def _check_deduction_amount(self): diff --git a/account_payment_multi_deduction/wizard/account_payment_register_views.xml b/account_payment_multi_deduction/wizard/account_payment_register_views.xml index 651ce2d91368..4246826b7d56 100644 --- a/account_payment_multi_deduction/wizard/account_payment_register_views.xml +++ b/account_payment_multi_deduction/wizard/account_payment_register_views.xml @@ -4,32 +4,31 @@ account.payment.register - -
-