Skip to content

Commit

Permalink
[FIX]sale_three_discounts: multiple errors
Browse files Browse the repository at this point in the history
closes #718

Signed-off-by: matiasperalta1 <mnp@adhoc.com.ar>
  • Loading branch information
jok-adhoc committed Nov 13, 2023
1 parent c12d0ff commit 9dfc548
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
1 change: 1 addition & 0 deletions sale_three_discounts/models/__init__.py
Expand Up @@ -4,4 +4,5 @@
##############################################################################

from . import sale_order_line
from . import sale_order
from . import account_invoice_line
19 changes: 19 additions & 0 deletions sale_three_discounts/models/sale_order.py
@@ -0,0 +1,19 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models


class SaleOrder(models.Model):

_inherit = "sale.order"

def _recompute_prices(self):
if self.pricelist_id.discount_policy == 'with_discount':
discount1 = {x: x.discount1 for x in self.order_line}
super()._recompute_prices()
for k, v in discount1.items():
k.discount1 = v
else:
super()._recompute_prices()
24 changes: 5 additions & 19 deletions sale_three_discounts/models/sale_order_line.py
Expand Up @@ -14,8 +14,6 @@ class SaleOrderLine(models.Model):
discount1 = fields.Float(
'Discount 1 (%)',
digits='Discount',
# compute = '_compute_discount1',
# readonly = False
)
discount2 = fields.Float(
'Discount 2 (%)',
Expand Down Expand Up @@ -93,23 +91,11 @@ def _compute_discounts(self):
(100.0 - discount) / 100.0)
rec.discount = 100.0 - (discount_factor * 100.0)

# @api.depends('product_id')
# def _compute_discount1(self):
# ds = {x: (x.discount2, x.discount3) for x in self}
# self.discount1, self.discount2, self.discount3, self.discount = 0,0,0,0
# import pdb;pdb.set_trace()
# super()._compute_discount()
# for k,v in ds.items():
# k.discount2, k.discount3 = v[0], v[1]
# for rec in self:
# rec.discount1 = rec.discount

# def _compute_discount(self):
# ds = {x: (x.discount2, x.discount3) for x in self}
# self.discount2, self.discount3 = 0,0
# super()._compute_discount()
# for k,v in ds.items():
# k.discount2, k.discount3 = v[0], v[1]
@api.onchange('product_id')
def _onchange_discounts(self):
self._compute_discount()
for rec in self:
rec.discount1 = rec.discount

def _prepare_invoice_line(self, **optional_values):
res = super()._prepare_invoice_line(**optional_values)
Expand Down

0 comments on commit 9dfc548

Please sign in to comment.