Skip to content

Commit

Permalink
[MIG] account_invoice_margin_sale: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ljsalvatierra-factorlibre committed Jun 5, 2023
1 parent 9d34172 commit c886a2a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion account_invoice_margin_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Account Invoice Margin Sale",
"summary": "Set margin in invoices from sale orders",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"development_status": "Production/Stable",
"maintainers": ["sergio-teruel", "carlosdauden"],
"category": "Account",
Expand Down
24 changes: 15 additions & 9 deletions account_invoice_margin_sale/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ class AccountMove(models.Model):
_inherit = "account.move"

def _get_margin_applicable_lines(self):
lines = super()._get_margin_applicable_lines()
return lines.filtered(lambda x: not x.sale_line_ids.is_downpayment)
invoice_lines = super()._get_margin_applicable_lines()
return invoice_lines.filtered(
lambda x: not any(x.sale_line_ids.mapped("is_downpayment"))
)


class AccountMoveLine(models.Model):
Expand All @@ -18,10 +20,14 @@ class AccountMoveLine(models.Model):
# pylint: disable=W8110
@api.depends("purchase_price", "price_subtotal")
def _compute_margin(self):
for line in self:
if any(line.sale_line_ids.mapped("is_downpayment")):
line.update(
{"margin": 0.0, "margin_signed": 0.0, "margin_percent": 0.0}
)
else:
super(AccountMoveLine, line)._compute_margin()
invoice_lines_with_downpayment = self.filtered(
lambda x: any(x.sale_line_ids.mapped("is_downpayment"))
)
invoice_lines_with_downpayment.update(
{
"margin": 0.0,
"margin_signed": 0.0,
"margin_percent": 0.0,
}
)
super(AccountMoveLine, self - invoice_lines_with_downpayment)._compute_margin()
4 changes: 4 additions & 0 deletions account_invoice_margin_sale/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
* `Open Source Integrators <https://www.opensourceintegrators.com>`__:

* Bhavesh Odedra

* `Factor Libre <https://www.factorlibre.com>`__:

* Luis J. Salvatierra
3 changes: 2 additions & 1 deletion account_invoice_margin_sale/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
This module allows transfer purchase price from sale order line to invoice.
This module propagates purchase price from sale order line to invoice and discards the
invoice lines coming from sale order lines with down-payment when computing the margin.
4 changes: 4 additions & 0 deletions account_invoice_margin_sale/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module also adds a security group.

#. To activate it go to user and active "Show Invoice Margin" in
security options.
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ class TestAccountInvoiceMargin(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.journal = cls.env["account.journal"].create(
{"name": "Test journal", "type": "sale", "code": "TEST_J"}
)
cls.account_type = cls.env["account.account.type"].create(
{
"name": "Test account type",
"type": "receivable",
"internal_group": "income",
}
)
cls.account = cls.env["account.account"].create(
{
"name": "Test account",
"code": "TEST_A",
"user_type_id": cls.account_type.id,
"code": "TESTACCRECV",
"account_type": "asset_receivable",
"reconcile": True,
}
)
Expand Down

0 comments on commit c886a2a

Please sign in to comment.