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 Jul 24, 2023
1 parent 2350456 commit 0f2a152
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 146 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.

37 changes: 37 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,37 @@
# 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.",
)

@api.onchange("discount_fixed")
def _onchange_discount_fixed(self):
"""When the discount fixed is changed, we set the ``discount`` on the line to the
appropriate value and apply the default downstream implementation.
When the display_type is not ``'product'`` we reset the discount_fixed to 0.0.
"""
if self.display_type != "product":
self.discount_fixed = 0.0
return

if self.discount_fixed:
self.discount = self.discount_fixed / self.price_unit * 100.0

@api.onchange("discount")
def _onchange_discount(self):
"""Reset the ``discount_fixed`` when ``discount`` is changed."""
if self.env.context.get("ignore_discount_fixed", False):
return
self.discount_fixed = 0.0
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,21 @@
# 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()
cls.partner = cls.env["res.partner"].create({"name": "Test"})
cls.product = cls.env.ref("product.product_product_3")
cls.account = cls.env["account.account"].search(
[
(
"user_type_id",
"=",
cls.env.ref("account.data_account_type_revenue").id,
)
],
[("account_type", "=", "income")],
limit=1,
)
type_current_liability = cls.env.ref(
"account.data_account_type_current_liabilities"
)
cls.output_vat_acct = cls.env["account.account"].create(
{"name": "10", "code": "10", "user_type_id": type_current_liability.id}
{"name": "10", "code": "10", "account_type": "liability_current"}
)
cls.tax_group_vat = cls.env["account.tax.group"].create({"name": "VAT"})
cls.vat = cls.env["account.tax"].create(
Expand Down
13 changes: 6 additions & 7 deletions account_invoice_fixed_discount/views/account_move_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
name="discount_fixed"
groups="base.group_no_one"
optional="show"
context="{'ignore_discount_fixed': True}"
/>
</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" />
</xpath>
<xpath
expr="//field[@name='line_ids']/tree/field[@name='discount']"
position="before"
>
<field name="discount_fixed" invisible="1" />
<field
name="discount_fixed"
groups="base.group_no_one"
context="{'ignore_discount_fixed': True}"
/>
</xpath>
</field>
</record>
Expand Down

0 comments on commit 0f2a152

Please sign in to comment.