summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/promotion/promotion_program_line.py
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-09-25 14:50:43 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-09-25 14:50:43 +0700
commit50b5bd7bd984ef108e8bd324440050a222d8262f (patch)
treefbd5f818fa3fbe716c41c73def6b104e8d124c36 /indoteknik_custom/models/promotion/promotion_program_line.py
parentdae4a3bf266ba4c19b1ba1d11c52ed9e19259b7c (diff)
Fix promotion program feature
Diffstat (limited to 'indoteknik_custom/models/promotion/promotion_program_line.py')
-rw-r--r--indoteknik_custom/models/promotion/promotion_program_line.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py
index a16f426d..34a0fbb2 100644
--- a/indoteknik_custom/models/promotion/promotion_program_line.py
+++ b/indoteknik_custom/models/promotion/promotion_program_line.py
@@ -7,7 +7,7 @@ class PromotionProgramLine(models.Model):
program_id = fields.Many2one('promotion.program', 'Program')
name = fields.Char('Name')
- type = fields.Selection([
+ promotion_type = fields.Selection([
("special_price", "Special Price"),
("bundling", "Bundling"),
("discount_loading", "Discount Loading"),
@@ -23,6 +23,11 @@ class PromotionProgramLine(models.Model):
free_product_ids = fields.One2many('promotion.free_product', 'program_line_id', 'Free Product')
price = fields.Float('Price')
+ discount_type = fields.Selection([
+ ("percentage", "Percentage"),
+ ("fixed", "Fixed")
+ ], 'Discount Type')
+ discount_amount = fields.Float('Discount Amount')
order_promotion_ids = fields.One2many('sale.order.promotion', 'program_line_id', 'Promotions')
@@ -62,10 +67,10 @@ class PromotionProgramLine(models.Model):
return remaining_qty
- def _res_type(self):
+ def _res_promotion_type(self):
return {
- 'value': self.type,
- 'label': dict(self._fields['type'].selection).get(self.type)
+ 'value': self.promotion_type,
+ 'label': dict(self._fields['promotion_type'].selection).get(self.promotion_type)
}
def _get_remaining_time(self):
@@ -97,7 +102,7 @@ class PromotionProgramLine(models.Model):
'name': self.name,
'image': ir_attachment.api_image(self._name, 'image', self.id),
'remaining_time': self._get_remaining_time(),
- 'type': self._res_type(),
+ 'promotion_type': self._res_promotion_type(),
'limit_qty': limit_qty,
'remaining_qty': remaining_qty,
'used_percentage': percent_remaining,
@@ -111,4 +116,19 @@ class PromotionProgramLine(models.Model):
'weight': weight
}
- return response \ No newline at end of file
+ if self.promotion_type == 'special_price':
+ response['price'] = self._calc_special_price_price(products[0])
+
+ return response
+
+ def _calc_special_price_price(self, product):
+ result = product['price']
+ price = result['price']
+ if self.discount_type == 'percentage':
+ result['discount_percentage'] = self.discount_amount
+ result['price_discount'] = price * (1 - self.discount_amount / 100)
+ elif self.discount_type == 'fixed':
+ final_price = price - self.discount_amount
+ result['price_discount'] = final_price
+ result['discount_percentage'] = (price - final_price) / price * 100
+ return result \ No newline at end of file