diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-26 09:38:27 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-26 09:38:27 +0700 |
| commit | c765b6ccc3da5051d7cb8e3997012fa6f46dd1f8 (patch) | |
| tree | 09d561db9c0024b6bd9d791decceac993152c076 | |
| parent | d454b715e7c7c31836cd525d9470b0eb3b1e7376 (diff) | |
Add source field on cart
| -rw-r--r-- | indoteknik_api/controllers/api_v1/cart.py | 9 | ||||
| -rw-r--r-- | indoteknik_custom/models/website_user_cart.py | 4 | ||||
| -rwxr-xr-x | indoteknik_custom/views/website_user_cart.xml | 2 |
3 files changed, 13 insertions, 2 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index 0265ec57..d712be4d 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -36,14 +36,16 @@ class Cart(controller.Controller): user_id = int(user_id) product_id = int(kw.get('product_id', 0)) qty = int(kw.get('qty', 0)) + source = kw.get('source') is_selected = kw.get('selected', 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 + is_selected = is_selected in ('true', True) + if not user_id or not product_id or not qty: return self.response(code=400, description='user_id, product_id and qty is required') + query = [('user_id', '=', user_id), ('product_id', '=', product_id)] cart = request.env['website.user.cart'].search(query, limit=1) result = {} @@ -52,6 +54,9 @@ class Cart(controller.Controller): 'is_selected': is_selected, 'program_line_id': program_line_id } + if source: + data_to_update['source'] = source + if cart: cart.write(data_to_update) result['id'] = cart.id diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 29bf4291..73f39d23 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -10,6 +10,10 @@ class WebsiteUserCart(models.Model): program_line_id = fields.Many2one('promotion.program.line', string='Program', help="Apply program") qty = fields.Float(string='Quantity', digits='Product Unit of Measure') is_selected = fields.Boolean(string='Selected?', digits='Is selected to process checkout') + source = fields.Selection([ + ('add_to_cart', 'Add To Cart'), + ('buy', 'Buy') + ], 'Source', default='add_to_cart') def get_product(self): user_data = { diff --git a/indoteknik_custom/views/website_user_cart.xml b/indoteknik_custom/views/website_user_cart.xml index fbd08acb..f942cdda 100755 --- a/indoteknik_custom/views/website_user_cart.xml +++ b/indoteknik_custom/views/website_user_cart.xml @@ -16,6 +16,7 @@ <field name="program_line_id"/> <field name="qty"/> <field name="is_selected"/> + <field name="source"/> </tree> </field> </record> @@ -33,6 +34,7 @@ <field name="program_line_id" domain="[('product_id', '=', product_id)]"/> <field name="qty"/> <field name="is_selected"/> + <field name="source"/> </group> <group></group> </group> |
