diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-09-23 11:50:20 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-09-23 11:50:20 +0700 |
| commit | dae4a3bf266ba4c19b1ba1d11c52ed9e19259b7c (patch) | |
| tree | 8858e0660aa004b582aedf6f437c0f455f8ad1ef /indoteknik_custom/models/website_user_cart.py | |
| parent | adbc9b985f1c5fb2b2f41f79c686b3a573003e62 (diff) | |
Update promotion program scheme
Diffstat (limited to 'indoteknik_custom/models/website_user_cart.py')
| -rw-r--r-- | indoteknik_custom/models/website_user_cart.py | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 1468e9dc..47a695fe 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -22,28 +22,33 @@ class WebsiteUserCart(models.Model): record.user_other_carts = others def get_product(self): - product = self.product_id.v2_api_single_response(self.product_id) - product['cart_id'] = self.id - product['quantity'] = self.qty - product['subtotal'] = self.qty * product['price']['price_discount'] - product['selected'] = self.is_selected - product['program'] = None - product['can_buy'] = True - flashsales = self.product_id._get_active_flash_sale() - product['has_flashsale'] = True if len(flashsales) > 0 else False - if self.program_line_id: + res = { + 'cart_id': self.id, + 'quantity': self.qty, + 'selected': self.is_selected, + 'can_buy': True + } + + if self.product_id: + res['cart_type'] = 'product' + product = self.product_id.v2_api_single_response(self.product_id) + res.update(product) + flashsales = self.product_id._get_active_flash_sale() + res['has_flashsale'] = True if len(flashsales) > 0 else False + elif self.program_line_id: + res['cart_type'] = 'promotion' userdata = { 'partner_id': self.user_id.partner_id.id, 'user_id': self.user_id.id } - product['program'] = self.program_line_id.format(user=userdata, qty=self.qty) - - if product['program']: - if self.qty < product['program']['minimum_purchase_qty'] or self.qty > product['program']['remaining_qty']['transaction']: - product['can_buy'] = False - product['price'] = product['program']['price'] - - return product + program = self.program_line_id.format(user=userdata, qty=self.qty) + res.update(program) + if program['remaining_qty']['transaction'] < self.qty: + res['can_buy'] = False + + res['subtotal'] = self.qty * res['price']['price_discount'] + + return res def get_products(self): return [x.get_product() for x in self] |
