-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] l10n_pt_sale_downpayment: Applied downpayments generate a Credi…
…t Note
- Loading branch information
Showing
5 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||