summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2024-01-04 09:25:14 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2024-01-04 09:25:14 +0700
commit717cb3b43c729e265603b3df61234c0b430742a7 (patch)
tree96b5547e395fc8cef46d679cbf4afee7d7dd729c
parentad127a4dc2bfb81d9c99ba78ab41a49eefeb0dd2 (diff)
update promotion program feature
-rw-r--r--indoteknik_custom/models/promotion/promotion_program.py1
-rw-r--r--indoteknik_custom/models/promotion/promotion_program_line.py9
-rw-r--r--indoteknik_custom/models/website_user_cart.py20
-rw-r--r--indoteknik_custom/views/promotion/promotion_program.xml1
-rw-r--r--indoteknik_custom/views/promotion/promotion_program_line.xml1
5 files changed, 23 insertions, 9 deletions
diff --git a/indoteknik_custom/models/promotion/promotion_program.py b/indoteknik_custom/models/promotion/promotion_program.py
index 29aaa753..1a1ee6bf 100644
--- a/indoteknik_custom/models/promotion/promotion_program.py
+++ b/indoteknik_custom/models/promotion/promotion_program.py
@@ -6,6 +6,7 @@ class PromotionProgram(models.Model):
name = fields.Char(string="Name")
banner = fields.Binary(string="Banner")
+ image = fields.Binary(string="Image")
icon = fields.Binary(string="Icon", help="Image 1:1 ratio")
icon_top = fields.Binary(string="Icon Top", help="Icon ini ditampilkan sebagai atribut pada atas gambar di product card pada website")
icon_bottom = fields.Binary(string="Icon Bottom", help="Icon ini ditampilkan sebagai atribut pada bawah gambar di product card pada website")
diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py
index d9095c75..d77123ce 100644
--- a/indoteknik_custom/models/promotion/promotion_program_line.py
+++ b/indoteknik_custom/models/promotion/promotion_program_line.py
@@ -13,7 +13,6 @@ class PromotionProgramLine(models.Model):
("discount_loading", "Discount Loading"),
("merchandise", "Merchandise")
], 'Type')
- image = fields.Binary(string="Image")
package_limit = fields.Integer('Package limit')
package_limit_user = fields.Integer('Package limit / user')
@@ -96,15 +95,15 @@ class PromotionProgramLine(models.Model):
weight = 0
if not any(x['package_weight'] == 0 for x in merged_products):
weight = sum(x['package_weight'] for x in merged_products)
-
- products_total = sum(x['price']['price_discount'] * x['qty'] for x in products)
- free_products_total = sum(x['price']['price_discount'] * x['qty'] for x in free_products)
+
+ # Sum of products and free products in 1 package quantity
+ products_total = sum(x['price']['price_discount'] * x['qty'] / qty for x in products)
+ free_products_total = sum(x['price']['price_discount'] * x['qty'] / qty for x in free_products)
package_price = products_total + free_products_total
response = {
'id': self.id,
'name': self.name,
- 'image': ir_attachment.api_image(self._name, 'image', self.id),
'remaining_time': self._get_remaining_time(),
'promotion_type': self._res_promotion_type(),
'limit_qty': limit_qty,
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index bbc14c88..eaa5f009 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -51,7 +51,9 @@ class WebsiteUserCart(models.Model):
return res
def get_products(self):
- return [x.get_product() for x in self]
+ products = [x.get_product() for x in self]
+
+ return products
def get_product_by_user(self, user_id, selected=False, source=False):
user_id = int(user_id)
@@ -75,8 +77,20 @@ class WebsiteUserCart(models.Model):
def get_user_checkout(self, user_id, voucher=False, source=False):
products = self.get_product_by_user(user_id=user_id, selected=True, source=source)
- total_purchase = sum(x['price']['price'] * x['quantity'] for x in products)
- total_discount = sum((x['price']['price'] - x['price']['price_discount']) * x['quantity'] for x in products)
+
+ total_purchase = 0
+ total_discount = 0
+ for product in products:
+ if product['cart_type'] == 'promotion':
+ price = product['package_price'] * product['quantity']
+ else:
+ price = product['price']['price'] * product['quantity']
+
+ discount_price = price - product['price']['price_discount'] * product['quantity']
+
+ total_purchase += price
+ total_discount += discount_price
+
subtotal = total_purchase - total_discount
discount_voucher = 0
if voucher:
diff --git a/indoteknik_custom/views/promotion/promotion_program.xml b/indoteknik_custom/views/promotion/promotion_program.xml
index f8432d8a..724f80c7 100644
--- a/indoteknik_custom/views/promotion/promotion_program.xml
+++ b/indoteknik_custom/views/promotion/promotion_program.xml
@@ -22,6 +22,7 @@
<group>
<field name="name" />
<field name="banner" widget="image" height="160" />
+ <field name="image" widget="image" height="160" />
<field name="keyword_ids" widget="many2many_tags" />
</group>
<group>
diff --git a/indoteknik_custom/views/promotion/promotion_program_line.xml b/indoteknik_custom/views/promotion/promotion_program_line.xml
index db6d5252..346a08c9 100644
--- a/indoteknik_custom/views/promotion/promotion_program_line.xml
+++ b/indoteknik_custom/views/promotion/promotion_program_line.xml
@@ -23,7 +23,6 @@
<group>
<field name="name" />
<field name="promotion_type" />
- <field name="image" widget="image" height="160" />
</group>
<group>
<field name="package_limit" />