Browse Source

Aug 22: [FIX] Bug Fixed 'all_in_one_purchase_kit'

pull/220/merge
Risvana Cybro 3 weeks ago
parent
commit
d7be667f73
  1. 37
      all_in_one_purchase_kit/models/purchase_order_line.py

37
all_in_one_purchase_kit/models/purchase_order_line.py

@ -39,8 +39,11 @@ class PurchaseOrderLine(models.Model):
string='Product Barcode', string='Product Barcode',
help="Here you can provide the barcode for the product") help="Here you can provide the barcode for the product")
discount = fields.Float( discount = fields.Float(
string="Discount (%)", editable=True, help="Total Discount" string="Discount (%)",
) compute='_compute_price_unit_and_date_planned_and_name',
digits='Discount',
store=True, readonly=False)
_sql_constraints = [ _sql_constraints = [
( (
"maximum_discount", "maximum_discount",
@ -88,22 +91,26 @@ class PurchaseOrderLine(models.Model):
vals.update({"price_unit": self._get_discounted_price()}) vals.update({"price_unit": self._get_discounted_price()})
return vals return vals
@api.onchange('product_id') def _compute_price_unit_and_date_planned_and_name(self):
def calculate_discount_percentage(self): result = super(PurchaseOrderLine, self)._compute_price_unit_and_date_planned_and_name()
"""Calculate the discount percentage"""
if not self.product_id or not self.order_id.partner_id:
return result
vendor = self.order_id.partner_id vendor = self.order_id.partner_id
sellers = self.product_id.product_tmpl_id.seller_ids sellers = self.product_id.product_tmpl_id.seller_ids
for rec in sellers:
if rec.partner_id.id == vendor.id: # Initialize with default discount first
if rec.discount: self.discount = vendor.default_discount or 0
self.write({'discount': rec.discount})
self.update({'price_unit': rec.price}) # Override with specific vendor discount if found
break for seller in sellers:
elif rec.partner_id.id != vendor.id: if seller.partner_id == vendor and seller.discount:
self.update({'discount': vendor.default_discount}) self.discount = seller.discount
self.price_unit = seller.price
break break
else:
self.write({'discount': None}) return result
@api.depends('discount') @api.depends('discount')
def _get_discounted_price(self): def _get_discounted_price(self):

Loading…
Cancel
Save