diff --git a/account_payment_line/wizard/__init__.py b/account_payment_line/wizard/__init__.py deleted file mode 100644 index 019698a882d..00000000000 --- a/account_payment_line/wizard/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import account_payment_register diff --git a/account_payment_line/wizard/account_payment_register.py b/account_payment_line/wizard/account_payment_register.py deleted file mode 100644 index cbd85fbe893..00000000000 --- a/account_payment_line/wizard/account_payment_register.py +++ /dev/null @@ -1,180 +0,0 @@ -# Copyright 2022 ForgeFlow, S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from odoo import api, fields, models -from odoo.models import MAGIC_COLUMNS -from odoo.tools import float_compare - - -class AccountPaymentRegister(models.TransientModel): - - _inherit = "account.payment.register" - - line_payment_counterpart_ids = fields.One2many( - "account.payment.register.counterpart.line", - "payment_id", - string="Counterpart Lines", - help="Use these lines to add matching lines, for example in a credit" - "card payment, financing interest or commission is added", - ) - - def _get_moves_domain(self): - current_invoices = ( - self.env.context.get("active_model") == "account.move" - and self.env.context.get("active_ids", []) - or [] - ) - if current_invoices: - domain = [("id", "in", current_invoices)] - return domain - - def _filter_amls(self, amls): - return amls.filtered( - lambda x: x.partner_id.commercial_partner_id.id - == self.partner_id.commercial_partner_id.id - and x.amount_residual != 0 - and x.account_id.internal_type in ("receivable", "payable") - ) - - def _hook_preprocess_lines(self): - return True - - @api.onchange( - "amount", - "currency_id", - "payment_date", - "journal_id", - ) - def onchange_payment_value(self): - move_model = self.env["account.move"] - domain = self._get_moves_domain() - pending_invoices = move_model.search(domain, order="invoice_date_due ASC") - extra_amount = ( - sum( - self.line_payment_counterpart_ids.filtered( - lambda x: x.extra_line - ).mapped("amount") - ) - * -1 - ) - pending_amount = self.amount + extra_amount - source_amount = 0 - if self.currency_id == self.source_currency_id: - source_amount = self.source_amount_currency - elif self.currency_id == self.company_id.currency_id: - source_amount = self.source_amount - else: - source_amount = self.company_id.currency_id._convert( - self.source_amount, - self.currency_id, - self.company_id, - self.payment_date or fields.Date.today(), - ) - if ( - float_compare( - pending_amount, - source_amount, - precision_rounding=self.currency_id.rounding, - ) - != 0 - ): - pending_amount = self.amount - lines = [] - for invoice in pending_invoices: - for aml in self._filter_amls(invoice.line_ids): - amount_to_apply = 0 - amount_residual = self.company_id.currency_id._convert( - aml.amount_residual, - self.currency_id, - self.company_id, - date=self.payment_date, - ) - if pending_amount >= 0: - amount_to_apply = min(abs(amount_residual), pending_amount) - pending_amount -= abs(amount_residual) - current_line = self.line_payment_counterpart_ids.filtered( - lambda x: x.aml_id.id == aml.id - ) - if len(current_line) == 1: - current_line.update({"amount": amount_to_apply}) - else: - lines.append( - { - "payment_id": self.id, - "name": "/", - "move_id": invoice.id, - "aml_id": aml.id, - "account_id": aml.account_id.id, - "partner_id": self.partner_id.commercial_partner_id.id, - "amount": amount_to_apply, - } - ) - if lines: - self.update( - { - "line_payment_counterpart_ids": lines - and [(0, 0, line) for line in lines] - or [] - } - ) - self._hook_preprocess_lines() - - def _create_payment_vals_from_wizard(self): - res = super()._create_payment_vals_from_wizard() - if self.payment_difference_handling != "reconcile": - lines_data = self.line_payment_counterpart_ids.read(load="_classic_write") - for line_data in lines_data: - for magic_field in MAGIC_COLUMNS: - if magic_field in lines_data: - line_data.pop(magic_field) - if "payment_id" in line_data: - line_data.pop("payment_id") - if lines_data: - res.update( - { - "line_payment_counterpart_ids": [ - (0, 0, line) for line in lines_data - ], - } - ) - return res - - @api.depends( - "amount", - "line_payment_counterpart_ids", - "line_payment_counterpart_ids.amount", - ) - def _compute_payment_difference(self): - res = super()._compute_payment_difference() - for wizard in self.filtered("line_payment_counterpart_ids"): - amount_lines = sum(wizard.line_payment_counterpart_ids.mapped("amount")) - wizard.payment_difference = wizard.amount - amount_lines - return res - - -class AccountPaymentRegisterCounterpartLine(models.TransientModel): - - _name = "account.payment.register.counterpart.line" - _inherit = "account.payment.counterpart.line.abstract" - _description = "Counterpart Lines on Invoice Wizard" - - payment_id = fields.Many2one( - "account.payment.register", string="Payment", required=False, ondelete="cascade" - ) - - analytic_tag_ids = fields.Many2many( - comodel_name="account.analytic.tag", - relation="counterpart_line_wizard_analytic_tag_rel", - column1="line_id", - column2="tag_id", - string="Analytic Tags", - domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", - check_company=True, - ) - - def _get_onchange_fields(self): - return ( - "aml_id.amount_residual", - "amount", - "payment_id.currency_id", - "payment_id.payment_date", - ) diff --git a/account_payment_line/wizard/account_payment_register_view.xml b/account_payment_line/wizard/account_payment_register_view.xml deleted file mode 100644 index 5a169d23356..00000000000 --- a/account_payment_line/wizard/account_payment_register_view.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - view.account.payment.register.line.tree - account.payment.register.counterpart.line - - - - - - - - - - - - - - - - - - - - - - - - - - account.payment.register.form - account.payment.register - - - - - - - - - - - - -