summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-11-13 13:30:27 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-11-13 13:30:27 +0700
commit001002a2c56d241cf2340155683f43a8c62ac7b6 (patch)
tree5c21a2a0489c3ea4d3ab668e431af7a9fde89af9
parentffec5d50ef5be0bea5dd9a658b54d053ed67344b (diff)
add free product to so line when promotion
-rw-r--r--indoteknik_api/controllers/api_v1/sale_order.py1
-rw-r--r--indoteknik_custom/models/promotion/sale_order.py10
-rwxr-xr-xindoteknik_custom/models/sale_order.py6
3 files changed, 14 insertions, 3 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py
index 905795b0..3e182a2e 100644
--- a/indoteknik_api/controllers/api_v1/sale_order.py
+++ b/indoteknik_api/controllers/api_v1/sale_order.py
@@ -464,6 +464,7 @@ class SaleOrder(controller.Controller):
if len(promotions) > 0:
sale_order.apply_promotion_program()
+ sale_order.add_free_product(promotions)
voucher_code = params['value']['voucher']
voucher = request.env['voucher'].search([('code', '=', voucher_code),('apply_type', 'in', ['all', 'brand'])], limit=1)
diff --git a/indoteknik_custom/models/promotion/sale_order.py b/indoteknik_custom/models/promotion/sale_order.py
index cb9a6f92..be820c6f 100644
--- a/indoteknik_custom/models/promotion/sale_order.py
+++ b/indoteknik_custom/models/promotion/sale_order.py
@@ -6,6 +6,16 @@ class SaleOrder(models.Model):
order_promotion_ids = fields.One2many('sale.order.promotion', 'order_id', 'Promotions')
+ def add_free_product(self, promotions):
+ for promotion in promotions:
+ program_line = self.env['promotion.program.line'].browse(promotion['program_line_id'])
+ for free_product in program_line.free_product_ids:
+ self.env['sale.order.line'].create({
+ 'order_id': self.id,
+ 'name': "Free Product " + free_product.product_id.display_name,
+ 'display_type': 'line_note'
+ })
+
def apply_promotion_program(self):
userdata = {
'user_id': self.partner_id.user_id.id,
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index e2399ecc..a0d70059 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -148,7 +148,7 @@ class SaleOrder(models.Model):
missing_weight_products = []
for line in self.order_line:
- if line.weight:
+ if line.weight > 0:
total_weight += line.weight * line.product_uom_qty
self.total_weight = total_weight
@@ -161,7 +161,7 @@ class SaleOrder(models.Model):
missing_weight_products = []
for line in self.order_line:
- if line.weight:
+ if line.weight > 0:
total_weight += line.weight * line.product_uom_qty
line.product_id.weight = line.weight
else:
@@ -186,7 +186,7 @@ class SaleOrder(models.Model):
missing_weight_products = []
for line in self.order_line:
- if line.weight:
+ if line.weight > 0:
total_weight += line.weight * line.product_uom_qty
line.product_id.weight = line.weight
else: