diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-09-26 10:20:59 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-09-26 10:20:59 +0700 |
| commit | 25a3271bd14671d57da6b4349745e446e94ebfef (patch) | |
| tree | d5a6554c61a02cd08f41c8068237a926e29874dd /indoteknik_custom/models/website_user_cart.py | |
| parent | bd8a83a76cea6ef2466c250226f7c95c38b3024c (diff) | |
| parent | 50b5bd7bd984ef108e8bd324440050a222d8262f (diff) | |
Merge branch 'change/feature/promotion-program' into production
# Conflicts:
# indoteknik_custom/models/sale_order.py
Diffstat (limited to 'indoteknik_custom/models/website_user_cart.py')
| -rw-r--r-- | indoteknik_custom/models/website_user_cart.py | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index b3695ba1..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): - user_data = { - 'partner_id': self.user_id.partner_id.id, - 'user_id': self.user_id.id + res = { + 'cart_id': self.id, + 'quantity': self.qty, + 'selected': self.is_selected, + 'can_buy': True } - 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 - product_flashsale = self.product_id._get_active_flash_sale() - product['has_flashsale'] = True if len(product_flashsale) > 0 else False - if self.program_line_id: - product['program'] = self.program_line_id.res_format_cart(user=user_data, quantity=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 + + 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 + } + 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] |
