Skip to content

Commit

Permalink
[16.0][IMP] account_global_discount: Remake amount global discount
Browse files Browse the repository at this point in the history
  • Loading branch information
Rferri44-S73 committed Jun 23, 2023
1 parent eaadd5a commit bb3d463
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion account_global_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Account Global Discount",
"version": "16.0.1.0.0",
"version": "16.0.1.1.0",
"category": "Accounting",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-invoicing",
Expand Down
55 changes: 30 additions & 25 deletions account_global_discount/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,42 +89,47 @@ def _set_global_discounts_by_tax(self):
for inv_line in _self.invoice_line_ids.filtered(
lambda l: l.display_type not in ["line_section", "line_note"]
):
for key in taxes_keys:
if key == tuple(inv_line.tax_ids.ids):
break
else:
taxes_keys[tuple(inv_line.tax_ids.ids)] = True
if inv_line.product_id.apply_global_discount:
for key in taxes_keys:
if key == tuple(inv_line.tax_ids.ids):
break
else:
taxes_keys[tuple(inv_line.tax_ids.ids)] = True
# Reset previous global discounts
self.invoice_global_discount_ids -= self.invoice_global_discount_ids
model = "account.invoice.global.discount"
create_method = in_draft_mode and self.env[model].new or self.env[model].create
for tax_line in _self.line_ids.filtered("tax_line_id"):
key = []
to_create = True
for key in taxes_keys:
if tax_line.tax_line_id.id in key:
to_create = taxes_keys[key]
taxes_keys[key] = False # mark for not duplicating
break # we leave in key variable the proper taxes value
if not to_create:
continue
base = tax_line.base_before_global_discounts or tax_line.tax_base_amount
for global_discount in self.global_discount_ids:
vals = self._prepare_global_discount_vals(global_discount, base, key)
create_method(vals)
base = vals["base_discounted"]
# Check all moves with defined taxes to check if there's any discount not
# created (tax amount is zero and only one tax is applied)
for line in _self.line_ids.filtered("tax_ids"):
key = tuple(line.tax_ids.ids)
if taxes_keys.get(key):
base = line.price_subtotal
if tax_line.product_id.apply_global_discount:
key = []
to_create = True
for key in taxes_keys:
if tax_line.tax_line_id.id in key:
to_create = taxes_keys[key]
taxes_keys[key] = False # mark for not duplicating
break # we leave in key variable the proper taxes value
if not to_create:
continue
base = tax_line.base_before_global_discounts or tax_line.tax_base_amount
for global_discount in self.global_discount_ids:
vals = self._prepare_global_discount_vals(
global_discount, base, key
)
create_method(vals)
base = vals["base_discounted"]
# Check all moves with defined taxes to check if there's any discount not
# created (tax amount is zero and only one tax is applied)
for line in _self.line_ids.filtered("tax_ids"):
if line.product_id.apply_global_discount:
key = tuple(line.tax_ids.ids)
if taxes_keys.get(key):
base = line.price_subtotal
for global_discount in self.global_discount_ids:
vals = self._prepare_global_discount_vals(
global_discount, base, key
)
create_method(vals)
base = vals["base_discounted"]

def _recompute_global_discount_lines(self):
"""Append global discounts move lines.
Expand Down
8 changes: 4 additions & 4 deletions account_global_discount/views/account_invoice_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@
<field
name="amount_untaxed_before_global_discounts"
string="Untaxed Amount Before Disc."
attrs="{'invisible': [('global_discount_ids', '=', [])]}"
attrs="{'invisible': ['|',('global_discount_ids', '=', []),('invoice_global_discount_ids','=',[])]}"
groups="base_global_discount.group_global_discount"
/>
<field
name="amount_untaxed_before_global_discounts"
string="Untaxed Amount Before Disc."
attrs="{'invisible': [('global_discount_ids_readonly', '=', [])]}"
attrs="{'invisible': ['|',('global_discount_ids_readonly', '=', []),('invoice_global_discount_ids','=',[])]}"
groups="!base_global_discount.group_global_discount"
/>
<field
name="amount_global_discount"
string="Global Discounts"
attrs="{'invisible': [('global_discount_ids', '=', [])]}"
attrs="{'invisible': ['|',('global_discount_ids', '=', []),('invoice_global_discount_ids','=',[])]}"
groups="base_global_discount.group_global_discount"
/>
<field
name="amount_global_discount"
string="Global Discounts"
attrs="{'invisible': [('global_discount_ids_readonly', '=', [])]}"
attrs="{'invisible': ['|',('global_discount_ids_readonly', '=', []),('invoice_global_discount_ids','=',[])]}"
groups="!base_global_discount.group_global_discount"
/>
</field>
Expand Down

0 comments on commit bb3d463

Please sign in to comment.