diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-18 16:38:29 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-18 16:38:29 +0700 |
| commit | d966917a5ba95074b6773f49fcb2c3c924296029 (patch) | |
| tree | 1522069c54c85dad7ec01ae9c16000034cde8878 | |
| parent | e0102841e6e21c7b583f096914aa4ba1a28e1587 (diff) | |
Fix lost merge voucher with promotion program
| -rw-r--r-- | indoteknik_api/controllers/api_v1/cart.py | 14 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/promotion.py | 6 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sale_order.py | 3 | ||||
| -rw-r--r-- | indoteknik_api/models/product_product.py | 5 | ||||
| -rw-r--r-- | indoteknik_custom/models/promotion_program.py | 7 | ||||
| -rw-r--r-- | indoteknik_custom/models/promotion_program_free_item.py | 6 | ||||
| -rw-r--r-- | indoteknik_custom/models/promotion_program_line.py | 24 | ||||
| -rw-r--r-- | indoteknik_custom/models/website_user_cart.py | 13 |
8 files changed, 41 insertions, 37 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index 035a40b7..0265ec57 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -37,7 +37,8 @@ class Cart(controller.Controller): product_id = int(kw.get('product_id', 0)) qty = int(kw.get('qty', 0)) is_selected = kw.get('selected', False) - program_line_id = int(kw.get('program_line_id', False)) + program_line_id = kw.get('program_line_id', False) + program_line_id = False if program_line_id == 'null' or not program_line_id else int(program_line_id) if is_selected: is_selected = True if is_selected == 'true' else False @@ -46,18 +47,19 @@ class Cart(controller.Controller): query = [('user_id', '=', user_id), ('product_id', '=', product_id)] cart = request.env['website.user.cart'].search(query, limit=1) result = {} + data_to_update = { + 'qty': qty, + 'is_selected': is_selected, + 'program_line_id': program_line_id + } if cart: - data_to_update = {'qty': qty, 'is_selected': is_selected} - if program_line_id: - data_to_update['program_line_id'] = program_line_id cart.write(data_to_update) result['id'] = cart.id else: create = request.env['website.user.cart'].create({ 'user_id': user_id, 'product_id': product_id, - 'qty': qty, - 'is_selected': is_selected + **data_to_update }) result['id'] = create.id diff --git a/indoteknik_api/controllers/api_v1/promotion.py b/indoteknik_api/controllers/api_v1/promotion.py index 68a23ef2..f84b8c1c 100644 --- a/indoteknik_api/controllers/api_v1/promotion.py +++ b/indoteknik_api/controllers/api_v1/promotion.py @@ -18,8 +18,7 @@ class Promotion(controller.Controller): data = {} id = int(id) - coupon_program = request.env['coupon.program'].search( - [('id', '=', id)]) + coupon_program = request.env['coupon.program'].search([('id', '=', id)]) if coupon_program: data = { 'banner': base_url + 'api/image/coupon.program/x_studio_banner_promo/' + str(coupon_program.id) if coupon_program.x_studio_banner_promo else '', @@ -37,7 +36,9 @@ class Promotion(controller.Controller): programs = request.env['promotion.program'].search([ ('start_time', '<=', current_time), ('end_time', '>=', current_time), + ('program_line.display_on_homepage', '=', True) ]) + if not programs: return self.response(None) @@ -85,5 +86,6 @@ class Promotion(controller.Controller): product.pop('price', None) product.pop('stock', None) data.append(product) + return self.response(data) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index a2e28cda..8135da33 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -275,7 +275,8 @@ class SaleOrder(controller.Controller): 'type': [], 'delivery_amount': ['number', 'default:0'], 'carrier_id': [], - 'delivery_service_type': [] + 'delivery_service_type': [], + 'voucher': [] }) if not params['valid']: diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 03742d69..334b58c5 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -48,6 +48,11 @@ class ProductProduct(models.Model): } return data + def has_active_program(self): + program_line = self.env['promotion.program.line'] + product_promotions = program_line.get_active_promotions(self.id) + return True if len(product_promotions) > 0 else False + def calculate_website_price(self): pricelist = self.env.user_pricelist diff --git a/indoteknik_custom/models/promotion_program.py b/indoteknik_custom/models/promotion_program.py index bc7f2c49..e60f48e1 100644 --- a/indoteknik_custom/models/promotion_program.py +++ b/indoteknik_custom/models/promotion_program.py @@ -15,8 +15,5 @@ class PromotionProgram(models.Model): ("all_user", "All User"), ("login_user", "Login User") ]) - program_line = fields.One2many( - comodel_name="promotion.program.line", inverse_name="program_id", string="Program Line") - keywords = fields.One2many( - comodel_name="promotion.program.keyword", inverse_name="program_id", string="Keywords" - ) + program_line = fields.One2many(comodel_name="promotion.program.line", inverse_name="program_id", string="Program Line") + keywords = fields.One2many(comodel_name="promotion.program.keyword", inverse_name="program_id", string="Keywords") diff --git a/indoteknik_custom/models/promotion_program_free_item.py b/indoteknik_custom/models/promotion_program_free_item.py index ddd97765..705456dd 100644 --- a/indoteknik_custom/models/promotion_program_free_item.py +++ b/indoteknik_custom/models/promotion_program_free_item.py @@ -5,8 +5,6 @@ class PromotionProgramFreeItem(models.Model): _name = "promotion.program.free_item" _rec_name = "product_id" - product_id = fields.Many2one( - comodel_name="product.product", string="Product Variant") + product_id = fields.Many2one(comodel_name="product.product", string="Product Variant") qty = fields.Integer(string="Qty") - line_id = fields.Many2one( - comodel_name="promotion.program.line", string="Program Line") + line_id = fields.Many2one(comodel_name="promotion.program.line", string="Program Line") diff --git a/indoteknik_custom/models/promotion_program_line.py b/indoteknik_custom/models/promotion_program_line.py index 7aaff4c4..077f7e12 100644 --- a/indoteknik_custom/models/promotion_program_line.py +++ b/indoteknik_custom/models/promotion_program_line.py @@ -7,10 +7,8 @@ class PromotionProgramLine(models.Model): name = fields.Char(string="Name") image = fields.Binary(string="Image") - product_id = fields.Many2one( - comodel_name="product.product", string="Product Variant") - program_id = fields.Many2one( - comodel_name="promotion.program", string="Program") + product_id = fields.Many2one(comodel_name="product.product", string="Product Variant") + program_id = fields.Many2one(comodel_name="promotion.program", string="Program") discount_type = fields.Selection(selection=[ ("percentage", "Percentage"), ("fixed_price", "Fixed Price"), @@ -22,18 +20,12 @@ class PromotionProgramLine(models.Model): ("discount_loading", "Discount Loading"), ("merchandise", "Merchandise") ], string="Promotion Type") - minimum_purchase_qty = fields.Integer( - string="Minimum Purchase Qty", help="Minimum Qty to applied discount loading") - applies_multiply = fields.Boolean( - string="Applies Multiply", help="Is applies multiply") - limit_qty = fields.Integer( - string="Limit Qty", help="Limit Qty product in promotion") - limit_qty_user = fields.Integer( - string="Limit Qty / User", help="Limit Qty per User") - limit_qty_transaction = fields.Integer( - string="Limit Qty / Transaction", help="Limit Qty per Transaction") - line_free_item = fields.One2many( - comodel_name="promotion.program.free_item", inverse_name="line_id", string="Line Free Item") + minimum_purchase_qty = fields.Integer(string="Minimum Purchase Qty", help="Minimum Qty to applied discount loading") + applies_multiply = fields.Boolean(string="Applies Multiply", help="Is applies multiply") + limit_qty = fields.Integer(string="Limit Qty", help="Limit Qty product in promotion") + limit_qty_user = fields.Integer(string="Limit Qty / User", help="Limit Qty per User") + limit_qty_transaction = fields.Integer(string="Limit Qty / Transaction", help="Limit Qty per Transaction") + line_free_item = fields.One2many(comodel_name="promotion.program.free_item", inverse_name="line_id", string="Line Free Item") display_on_homepage = fields.Boolean(string="Display on Homepage") order_line_ids = fields.One2many('sale.order.line', 'program_line_id') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 388151ab..a8cde228 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -16,14 +16,21 @@ class WebsiteUserCart(models.Model): 'partner_id': self.user_id.partner_id.id, 'user_id': self.user_id.id } - product_product = self.env['product.product'] - product = product_product.v2_api_single_response(self.product_id) + 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 if self.program_line_id: - product['program'] = self.program_line_id.res_format_cart(user_data) + 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 def get_products(self): |
