Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] l10n_pt_sale_downpayment: Applied downpayments generate a Credit Note #104

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions l10n_pt_sale_downpayment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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
29 changes: 29 additions & 0 deletions l10n_pt_sale_downpayment/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (C) 2023 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import 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

Check warning on line 26 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

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

Check warning on line 29 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#L28-L29

Added lines #L28 - L29 were not covered by tests
6 changes: 6 additions & 0 deletions setup/l10n_pt_sale_downpayment/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading