diff options
| -rw-r--r-- | fixco_custom/models/purchase_order.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/fixco_custom/models/purchase_order.py b/fixco_custom/models/purchase_order.py index b4adb7d..43fe8f6 100644 --- a/fixco_custom/models/purchase_order.py +++ b/fixco_custom/models/purchase_order.py @@ -1,3 +1,4 @@ +from shutil import copy from odoo import fields, models, api, _ from odoo.exceptions import AccessError, UserError, ValidationError from dateutil.relativedelta import relativedelta @@ -55,7 +56,7 @@ class PurchaseOrder(models.Model): soo_price = fields.Float('SOO Price', copy=False) soo_discount = fields.Float('SOO Discount', copy=False) soo_tax = fields.Float('SOO Tax', copy=False) - discount_total = fields.Float('Discount Total', help = 'Total Discount for Each Product') + discount_total = fields.Float('Discount Total', help = 'Total Discount for Each Product', copy=False, default=0.0) def _get_fixco_token(self, source='auto'): ICP = self.env['ir.config_parameter'].sudo() @@ -426,14 +427,18 @@ class PurchaseOrder(models.Model): 'domain': [('id', 'in', journals.ids)], } - @api.depends('order_line.price_total', 'biaya_lain_lain', 'discount_total') + @api.depends('order_line.price_total', 'biaya_lain_lain', 'discount_total', 'amount_tax', 'amount_discount') def _amount_all(self): super(PurchaseOrder, self)._amount_all() for order in self: - total_discount = order._get_line_discount_total + order.discount_total + line_discount = 0.0 + for line in order.order_line: + if line.discount > 0: + line_discount += line.discount_amount + amount_total = order.amount_untaxed + order.amount_tax + order.biaya_lain_lain - order.discount_total - order.amount_discount = total_discount + order.amount_discount = order.discount_total + line_discount order.amount_total = order.currency_id.round(amount_total) @api.depends('order_line.discount_amount') |
