diff --git a/l10n_pt_sale_downpayment/README.rst b/l10n_pt_sale_downpayment/README.rst new file mode 100644 index 00000000..1333ed77 --- /dev/null +++ b/l10n_pt_sale_downpayment/README.rst @@ -0,0 +1 @@ +TODO diff --git a/l10n_pt_sale_downpayment/__init__.py b/l10n_pt_sale_downpayment/__init__.py new file mode 100644 index 00000000..6a0c7727 --- /dev/null +++ b/l10n_pt_sale_downpayment/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/l10n_pt_sale_downpayment/__manifest__.py b/l10n_pt_sale_downpayment/__manifest__.py new file mode 100644 index 00000000..44212e56 --- /dev/null +++ b/l10n_pt_sale_downpayment/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Applied downpayments generate a Credit Note", + "summary": "Credit the original down payment invoice " + "and avoid negative invoice lines", + "version": "16.0.1.0.0", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "license": "AGPL-3", + "website": "https://github.com/OCA/l10n-portugal", + "category": "Accounting/Localizations/EDI", + "maintainers": ["dreispt"], + "development_status": "Beta", + "depends": ["sale"], + "data": [ + ], + "images": ["static/description/cover.png"], + "application": True, + "installable": True, +} diff --git a/l10n_pt_sale_downpayment/models/__init__.py b/l10n_pt_sale_downpayment/models/__init__.py new file mode 100644 index 00000000..399ff84b --- /dev/null +++ b/l10n_pt_sale_downpayment/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2023 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import sale_order diff --git a/l10n_pt_sale_downpayment/models/sale_order.py b/l10n_pt_sale_downpayment/models/sale_order.py new file mode 100644 index 00000000..b761f23b --- /dev/null +++ b/l10n_pt_sale_downpayment/models/sale_order.py @@ -0,0 +1,30 @@ +# Copyright (C) 2023 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, exceptions, fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _create_invoices(self, grouped=False, final=False, date=None): + moves = super()._create_invoices(grouped=grouped, final=final, date=date) + moves_downp = moves.filtered(lambda x: x.line_ids.filtered("is_downpayment")) + reverts = self.env["account.move"] + for move_dp in moves_downp: + revert_dp = move_dp.copy() + reverts |= revert_dp + move_lines_to_unlink = move_dp.invoice_line_ids.filtered( + lambda x: x.is_downpayment and x.price_subtotal < 0 + ) + move_lines_to_unlink.unlink() + revert_lines_to_unlink = revert_dp.invoice_line_ids.filtered( + lambda x: not (x.is_downpayment and x.price_subtotal < 0) + ) + revert_lines_to_unlink.unlink() + # Keep link with Sale Order + so_lines = move_dp.invoice_line_ids.sale_line_ids + import pudb; pu.db + for line in revert_dp.invoice_line_ids: + line.sale_line_ids |= so_lines + return moves