Skip to content

Commit

Permalink
[MIG] account_invoice_fixed_discount: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PieterPaulussen committed Jun 20, 2023
1 parent 755f7cd commit 2720195
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 135 deletions.
2 changes: 1 addition & 1 deletion account_invoice_fixed_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Account Fixed Discount",
"summary": "Allows to apply fixed amount discounts in invoices.",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/account-invoicing",
"author": "ForgeFlow, Odoo Community Association (OCA)",
Expand Down
2 changes: 1 addition & 1 deletion account_invoice_fixed_discount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from . import account_move
from . import account_move_line
124 changes: 0 additions & 124 deletions account_invoice_fixed_discount/models/account_move.py

This file was deleted.

36 changes: 36 additions & 0 deletions account_invoice_fixed_discount/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2017 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import _, api, fields, models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

discount_fixed = fields.Float(
string="Discount (Fixed)",
digits="Product Price",
default=0.00,
help="Fixed amount discount.",
compute="_compute_totals",
inverse="_inverse_discount_fixed",
compute_sudo=True,
store=True,
)

def _inverse_discount_fixed(self):
"""When a fixed discount is provided, recompute discount and pass downstream."""
for line in self:
if line.discount_fixed != 0:
line.discount = (line.discount_fixed / line.price_unit) * 100 or 0.0

@api.depends("quantity", "discount", "price_unit", "tax_ids", "currency_id", "discount_fixed")
def _compute_totals(self):
"""Depending on the discount fields, decide which one to use."""
for line in self:
if line._origin and line.discount != line._origin.discount:
line.discount_fixed = 0.0
if line.discount_fixed != 0:
line.discount = (line.discount_fixed / line.price_unit) * 100 or 0.0

return super()._compute_totals()
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo.exceptions import ValidationError
from odoo.tests import TransactionCase
from odoo.tests import SavepointCase


class TestInvoiceFixedDiscount(TransactionCase):
class TestInvoiceFixedDiscount(SavepointCase):
@classmethod
def setUpClass(cls):
super(TestInvoiceFixedDiscount, cls).setUpClass()
Expand Down
10 changes: 3 additions & 7 deletions account_invoice_fixed_discount/views/account_move_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@
expr="//field[@name='invoice_line_ids']/tree/field[@name='discount']"
position="before"
>
<field
name="discount_fixed"
groups="base.group_no_one"
optional="show"
/>
<field name="discount_fixed" optional="show"/>
</xpath>
<xpath
expr="//field[@name='invoice_line_ids']/form/sheet/group/field[@name='discount']"
position="before"
>
<field name="discount_fixed" groups="base.group_no_one" />
<field name="discount_fixed" />
</xpath>
<xpath
expr="//field[@name='line_ids']/tree/field[@name='discount']"
expr="//field[@name='line_ids']/tree/field[@name='discount_amount_currency']"
position="before"
>
<field name="discount_fixed" invisible="1" />
Expand Down

0 comments on commit 2720195

Please sign in to comment.