-
-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] account_invoice_fixed_discount: Migration to 16.0
- Loading branch information
1 parent
2350456
commit 532213c
Showing
6 changed files
with
61 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
account_invoice_fixed_discount/models/account_move_line.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2017 ForgeFlow S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
def _recompute_tax_lines( | ||
self, recompute_tax_base_amount=False, tax_rep_lines_to_recompute=None | ||
): | ||
vals = {} | ||
for line in self.invoice_line_ids.filtered("discount_fixed"): | ||
vals[line] = {"price_unit": line.price_unit} | ||
price_unit = line.price_unit - line.discount_fixed | ||
line.update({"price_unit": price_unit}) | ||
res = super(AccountMove, self)._recompute_tax_lines( | ||
recompute_tax_base_amount=recompute_tax_base_amount, | ||
tax_rep_lines_to_recompute=tax_rep_lines_to_recompute, | ||
) | ||
for line in vals.keys(): | ||
line.update(vals[line]) | ||
return res | ||
|
||
|
||
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.""" | ||
self.discount_fixed = 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters