-
-
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
755f7cd
commit 2720195
Showing
6 changed files
with
43 additions
and
135 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.
36 changes: 36 additions & 0 deletions
36
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,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() |
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