summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/website_user_cart.py
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-07-18 13:59:18 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-07-18 13:59:18 +0700
commit45fd501a53c6997bf74d5927d7c0eecf387caa51 (patch)
treefa20bdff3e95d943b0f4846b9746767f87f70f31 /indoteknik_custom/models/website_user_cart.py
parent999725ea036840d74c7fdeebbd3aefac772bd8d3 (diff)
parentd418bd8dd84b91b9dc031819cfa9a2446e77acd2 (diff)
Merge branch 'origin/feature/promotion-program' into feature/voucher-cart
Diffstat (limited to 'indoteknik_custom/models/website_user_cart.py')
-rw-r--r--indoteknik_custom/models/website_user_cart.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index 8046469f..388151ab 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -5,6 +5,35 @@ class WebsiteUserCart(models.Model):
_name = 'website.user.cart'
_rec_name = 'user_id'
- user_id = fields.Many2one('res.users', string='User', help="User ID yang terdaftar di table res.users")
- product_id = fields.Many2one('product.product', string='Product', help="Product yang terdaftar di table product.product")
+ user_id = fields.Many2one('res.users', string='User')
+ product_id = fields.Many2one('product.product', string='Product')
+ 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')
+
+ def get_product(self):
+ user_data = {
+ '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['quantity'] = self.qty
+ product['subtotal'] = self.qty * product['price']['price_discount']
+ product['selected'] = self.is_selected
+ product['program'] = None
+ if self.program_line_id:
+ product['program'] = self.program_line_id.res_format_cart(user_data)
+ return product
+
+ def get_products(self):
+ return [x.get_product() for x in self]
+
+ def get_product_by_user(self, user_id, selected = False):
+ user_id = int(user_id)
+ parameters = [('user_id', '=', user_id)]
+ if selected:
+ parameters.append(('is_selected', '=', True))
+ carts = self.search(parameters)
+ products = carts.get_products()
+ return products \ No newline at end of file