Skip to content

Commit

Permalink
[ADD] l10n_pt_sale_downpayment: Applied downpayments generate a Credi…
Browse files Browse the repository at this point in the history
…t Note
  • Loading branch information
dreispt committed Dec 30, 2023
1 parent 9a87b7c commit 5897bbf
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions l10n_pt_sale_downpayment/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
4 changes: 4 additions & 0 deletions l10n_pt_sale_downpayment/__init__.py
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
21 changes: 21 additions & 0 deletions l10n_pt_sale_downpayment/__manifest__.py
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,
}
4 changes: 4 additions & 0 deletions l10n_pt_sale_downpayment/models/__init__.py
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
30 changes: 30 additions & 0 deletions l10n_pt_sale_downpayment/models/sale_order.py
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)

Check warning on line 11 in l10n_pt_sale_downpayment/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_sale_downpayment/models/sale_order.py#L11

Added line #L11 was not covered by tests
moves_downp = moves.filtered(lambda x: x.line_ids.filtered("is_downpayment"))
reverts = self.env["account.move"]

Check warning on line 13 in l10n_pt_sale_downpayment/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_sale_downpayment/models/sale_order.py#L13

Added line #L13 was not covered by tests
for move_dp in moves_downp:
revert_dp = move_dp.copy()
reverts |= revert_dp

Check warning on line 16 in l10n_pt_sale_downpayment/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_sale_downpayment/models/sale_order.py#L15-L16

Added lines #L15 - L16 were not covered by tests
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()

Check warning on line 20 in l10n_pt_sale_downpayment/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_sale_downpayment/models/sale_order.py#L20

Added line #L20 was not covered by tests
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()

Check warning on line 24 in l10n_pt_sale_downpayment/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_sale_downpayment/models/sale_order.py#L24

Added line #L24 was not covered by tests
# Keep link with Sale Order
so_lines = move_dp.invoice_line_ids.sale_line_ids
import pudb; pu.db

Check warning on line 27 in l10n_pt_sale_downpayment/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_sale_downpayment/models/sale_order.py#L26-L27

Added lines #L26 - L27 were not covered by tests
for line in revert_dp.invoice_line_ids:
line.sale_line_ids |= so_lines
return moves

Check warning on line 30 in l10n_pt_sale_downpayment/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_sale_downpayment/models/sale_order.py#L29-L30

Added lines #L29 - L30 were not covered by tests

0 comments on commit 5897bbf

Please sign in to comment.