From fa6e8c91bd98100b6ef862ce388817515f77b55d Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 12 Aug 2024 13:15:25 +0700 Subject: add api tracking order --- indoteknik_api/controllers/api_v1/sale_order.py | 33 ++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index ee173d29..d44868f0 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -615,4 +615,35 @@ class SaleOrder(controller.Controller): } return self.response(data) - \ No newline at end of file + + @http.route(prefix + 'tracking_order', auth='public', method=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def tracking_get_sale_order_detail(self, **kw): + # Extract 'so' and 'email' parameters from query parameters + so = kw.get('so') + email_user = kw.get('email') + + if not email_user or not so: + return self.response(code=400, description="Email and Sale Order number are required.") + + # Search for the sale order by the name (so) + sale_order = request.env['sale.order'].search([('name', '=', so)], limit=1) + if not sale_order: + return self.response(code=404, description="Sale Order not found.") + + # Get the partner associated with the sale order + partner = sale_order.partner_id + + # Check if the email matches the partner's email + if partner.email != email_user: + return self.response(code=403, description="Email does not match the Sale Order.") + + # Check for partner child ids if needed + partner_child_ids = self.get_partner_child_ids(partner.id) + if sale_order.partner_id.id not in partner_child_ids: + return self.response(code=403, description="Unauthorized access to Sale Order details.") + + # Prepare the response data + data = request.env['sale.order'].api_v1_single_response(sale_order, context='with_detail') + + return self.response(data) \ No newline at end of file -- cgit v1.2.3 From 57bc06d6991f4ab2f0f0ef4baecbf071eb62042a Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 12 Aug 2024 16:32:06 +0700 Subject: update api tracking order --- indoteknik_api/controllers/api_v1/sale_order.py | 29 ++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index d44868f0..a9113ada 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -624,26 +624,45 @@ class SaleOrder(controller.Controller): email_user = kw.get('email') if not email_user or not so: - return self.response(code=400, description="Email and Sale Order number are required.") + return self.response({ + 'code': 400, + 'so': so, + 'email': email_user, + 'description': "Email and Sale Order number are required." + }) # Search for the sale order by the name (so) sale_order = request.env['sale.order'].search([('name', '=', so)], limit=1) if not sale_order: - return self.response(code=404, description="Sale Order not found.") + return self.response({ + 'code': 404, + 'so': so, + 'email': email_user, + 'description': "Sale Order not found." + }) # Get the partner associated with the sale order partner = sale_order.partner_id # Check if the email matches the partner's email if partner.email != email_user: - return self.response(code=403, description="Email does not match the Sale Order.") + return self.response({ + 'code': 403, + 'so': so, + 'email': email_user, + 'description': "Email does not match the Sale Order." + }) # Check for partner child ids if needed partner_child_ids = self.get_partner_child_ids(partner.id) if sale_order.partner_id.id not in partner_child_ids: - return self.response(code=403, description="Unauthorized access to Sale Order details.") + return self.response({ + 'so': so, + 'email': email_user, + 'description': "Unauthorized access to Sale Order details." + }) # Prepare the response data data = request.env['sale.order'].api_v1_single_response(sale_order, context='with_detail') - return self.response(data) \ No newline at end of file + return self.response(data) -- cgit v1.2.3 From 2513b765773fca587dbd298e77732d2d005949c8 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 13 Aug 2024 11:24:51 +0700 Subject: update api tracking order to get email same partner in company --- indoteknik_api/controllers/api_v1/sale_order.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index a9113ada..0da7f894 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -643,20 +643,26 @@ class SaleOrder(controller.Controller): # Get the partner associated with the sale order partner = sale_order.partner_id + company_id = partner.company_id.id - # Check if the email matches the partner's email - if partner.email != email_user: + # Search for all partners within the same company + partners_in_company = request.env['res.partner'].search([('company_id', '=', company_id)]) + + # Check if the email matches any partner's email in the same company + email_match = partners_in_company.filtered(lambda p: p.email == email_user) + if not email_match: return self.response({ 'code': 403, 'so': so, 'email': email_user, - 'description': "Email does not match the Sale Order." + 'description': "Email does not match any partner in the same company as the Sale Order." }) # Check for partner child ids if needed partner_child_ids = self.get_partner_child_ids(partner.id) if sale_order.partner_id.id not in partner_child_ids: return self.response({ + 'code': 403, 'so': so, 'email': email_user, 'description': "Unauthorized access to Sale Order details." @@ -666,3 +672,4 @@ class SaleOrder(controller.Controller): data = request.env['sale.order'].api_v1_single_response(sale_order, context='with_detail') return self.response(data) + -- cgit v1.2.3 From 857fbbf8a46c9b933bd3fb13d274fbed2f3fea39 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 27 Aug 2024 10:08:47 +0700 Subject: add required to public_categ_ids product template & variant --- indoteknik_custom/models/product_template.py | 12 ++++++++++++ indoteknik_custom/views/product_template.xml | 3 +++ 2 files changed, 15 insertions(+) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index d51f903f..e6778758 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -61,6 +61,12 @@ class ProductTemplate(models.Model): tkdn = fields.Boolean(string='TKDN') short_spesification = fields.Char(string='Short Spesification') + @api.constrains('name', 'internal_reference', 'x_manufacture') + def required_public_categ_ids(self): + for rec in self: + if not rec.public_categ_ids: + raise UserError('Field Categories harus diisi') + def _get_qty_sold(self): for rec in self: rec.qty_sold = sum(x.qty_sold for x in rec.product_variant_ids) @@ -367,6 +373,12 @@ class ProductProduct(models.Model): qty_sold = fields.Float(string='Sold Quantity', compute='_get_qty_sold') short_spesification = fields.Char(string='Short Spesification') + @api.constrains('name', 'internal_reference', 'x_manufacture') + def required_public_categ_ids(self): + for rec in self: + if not rec.public_categ_ids: + raise UserError('Field Categories harus diisi') + @api.constrains('active') def archive_product(self): for product in self: diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index 520af5c8..e3a39412 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -21,6 +21,9 @@ + + 1 + -- cgit v1.2.3 From d776b60f89f827d2dc49df80d7852f98c820985f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 27 Aug 2024 13:42:55 +0700 Subject: deactivate function check data vendor on po --- indoteknik_custom/models/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 3a11ab1e..8ec904a9 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -435,7 +435,7 @@ class PurchaseOrder(models.Model): res = super(PurchaseOrder, self).button_confirm() current_time = datetime.now() self.check_ppn_mix() - self.check_data_vendor() + # self.check_data_vendor() if self.total_percent_margin < self.total_so_percent_margin and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: raise UserError("Beda Margin dengan Sales, harus approval Manager") -- cgit v1.2.3 From a321d5437ae7b43a6839a1332f3c14e2aca0d953 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 28 Aug 2024 16:43:57 +0700 Subject: add api picking if no login --- indoteknik_api/controllers/api_v1/stock_picking.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/indoteknik_api/controllers/api_v1/stock_picking.py b/indoteknik_api/controllers/api_v1/stock_picking.py index 5e919b31..8b941c16 100644 --- a/indoteknik_api/controllers/api_v1/stock_picking.py +++ b/indoteknik_api/controllers/api_v1/stock_picking.py @@ -99,3 +99,15 @@ class StockPicking(controller.Controller): return self.response(None) return self.response(picking.get_tracking_detail()) + + @http.route(prefix + 'stock-picking//tracking', auth='public', method=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def get_partner_stock_picking_detail_tracking_iman(self, **kw): + id = int(kw.get('id', 0)) + picking_model = request.env['stock.picking'] + + picking = picking_model.browse(id) + if not picking: + return self.response(None) + + return self.response(picking.get_tracking_detail()) \ No newline at end of file -- cgit v1.2.3 From f4c67f4f8ef9ffc9da3e0406cb08fffb6ba44fd4 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 10:26:52 +0700 Subject: add options no create on product template and variants --- indoteknik_custom/views/product_template.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index e3a39412..b6155eea 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -8,7 +8,7 @@ - + @@ -24,6 +24,9 @@ 1 + + {'no_create': True} + -- cgit v1.2.3 From 0e9e58da406e62a72ce2ba18c6317e3de57963a1 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 13:09:54 +0700 Subject: cr api voucher --- indoteknik_api/controllers/api_v1/sale_order.py | 16 +++++++++++++--- indoteknik_custom/models/website_user_cart.py | 20 ++++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index b351bacc..f6417bf9 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -342,11 +342,21 @@ class SaleOrder(controller.Controller): @http.route(prefix + 'user//sale_order/checkout', auth='public', method=['GET', 'OPTIONS'], csrf=False) @controller.Controller.must_authorized(private=True, private_key='user_id') def get_user_checkout_so(self, user_id, **kw): - cart = request.env['website.user.cart'] + m_voucher = request.env['voucher'] + m_cart = request.env['website.user.cart'] + voucher_code = kw.get('voucher') + voucher_shipping_code = kw.get('voucher_shipping') source = kw.get('source') - voucher = request.env['voucher'].search([('code', '=', voucher_code)], limit=1) - result = cart.with_context(price_for="web").get_user_checkout(user_id, voucher, source) + + voucher = m_voucher.search([('code', '=', voucher_code)], limit=1) + voucher_shipping = m_voucher.search([('code', '=', voucher_shipping_code)], limit=1) + result = m_cart.with_context(price_for="web").get_user_checkout( + user_id, + voucher=voucher, + voucher_shipping=voucher_shipping, + source=source + ) return self.response(result) @http.route(PREFIX_PARTNER + 'sale_order/checkout', auth='public', method=['POST', 'OPTIONS'], csrf=False) diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index d9352abb..c233dfd7 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -91,7 +91,7 @@ class WebsiteUserCart(models.Model): products = carts.get_products() return products - def get_user_checkout(self, user_id, voucher=False, source=False): + def get_user_checkout(self, user_id, voucher=False, voucher_shipping=False, source=False): products = self.get_product_by_user(user_id=user_id, selected=True, source=source) total_purchase = 0 @@ -109,12 +109,12 @@ class WebsiteUserCart(models.Model): subtotal = total_purchase - total_discount discount_voucher = 0 - if voucher: - order_line = [] + discount_voucher_shipping = 0 + order_line = [] + + if voucher or voucher_shipping: for product in products: - if product['cart_type'] == 'promotion': - continue - + if product['cart_type'] == 'promotion': continue order_line.append({ 'product_id': self.env['product.product'].browse(product['id']), 'price': product['price']['price'], @@ -122,9 +122,16 @@ class WebsiteUserCart(models.Model): 'qty': product['quantity'], 'subtotal': product['subtotal'] }) + + if voucher: voucher_info = voucher.apply(order_line) discount_voucher = voucher_info['discount']['all'] subtotal -= discount_voucher + + if voucher_shipping: + voucher_shipping_info = voucher_shipping.apply(order_line) + discount_voucher_shipping = voucher_shipping_info['discount']['all'] + tax = round(subtotal * 0.11) grand_total = subtotal + tax total_weight = sum(x['weight'] * x['quantity'] for x in products) @@ -133,6 +140,7 @@ class WebsiteUserCart(models.Model): 'total_purchase': total_purchase, 'total_discount': total_discount, 'discount_voucher': discount_voucher, + 'discount_voucher_shipping': discount_voucher_shipping, 'subtotal': subtotal, 'tax': tax, 'grand_total': round(grand_total), -- cgit v1.2.3 From 18e3b9d7abe9210c74b321fda489a049795774a2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 13:30:18 +0700 Subject: add attrs to payment term po --- indoteknik_custom/views/purchase_order.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 25b7787b..b936086a 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -39,7 +39,7 @@ - + -- cgit v1.2.3 From 1b2d9c35be0e48e4aadc8d6e2578fd623ad7d03a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 14:29:26 +0700 Subject: fix bug voucher --- indoteknik_custom/models/voucher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/voucher.py b/indoteknik_custom/models/voucher.py index f7305999..37c97338 100644 --- a/indoteknik_custom/models/voucher.py +++ b/indoteknik_custom/models/voucher.py @@ -146,7 +146,7 @@ class Voucher(models.Model): def calc_discount_amount(self, total): result = { 'all': 0, 'brand': {} } - if self.apply_type == 'all': + if self.apply_type in ['all', 'shipping']: if total['all'] < self.min_purchase_amount: return result -- cgit v1.2.3 From 00b552bcdd7a689cf347aa2b882ec6796f42bc20 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 14:38:17 +0700 Subject: fix voucher --- indoteknik_custom/models/website_user_cart.py | 1 + 1 file changed, 1 insertion(+) diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index c233dfd7..0af22d47 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -131,6 +131,7 @@ class WebsiteUserCart(models.Model): if voucher_shipping: voucher_shipping_info = voucher_shipping.apply(order_line) discount_voucher_shipping = voucher_shipping_info['discount']['all'] + subtotal -= discount_voucher_shipping tax = round(subtotal * 0.11) grand_total = subtotal + tax -- cgit v1.2.3 From f1b4d965f17184fb1a44c4bda759bd5a23f9df8d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 15:23:13 +0700 Subject: fix voucher --- indoteknik_api/controllers/api_v1/sale_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index f6417bf9..1b7c1af4 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -349,8 +349,8 @@ class SaleOrder(controller.Controller): voucher_shipping_code = kw.get('voucher_shipping') source = kw.get('source') - voucher = m_voucher.search([('code', '=', voucher_code)], limit=1) - voucher_shipping = m_voucher.search([('code', '=', voucher_shipping_code)], limit=1) + voucher = m_voucher.search([('code', '=', voucher_code), ('apply_type', 'in', ['all', 'brand'])], limit=1) + voucher_shipping = m_voucher.search([('code', '=', voucher_shipping_code), ('apply_type', '=', 'shipping')], limit=1) result = m_cart.with_context(price_for="web").get_user_checkout( user_id, voucher=voucher, -- cgit v1.2.3 From 2719b8cdd45b356baa598255dcdbdd8e353478e7 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 30 Aug 2024 10:13:44 +0700 Subject: payment term po cr --- indoteknik_custom/models/automatic_purchase.py | 1 + indoteknik_custom/views/purchase_order.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 3561fc0f..1d1322fa 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -220,6 +220,7 @@ class AutomaticPurchase(models.Model): # i start from zero (0) for i in range(page): new_po = self.env['purchase.order'].create([param_header]) + new_po.payment_term_id = new_po.partner_id.property_supplier_payment_term_id new_po.name = new_po.name + name + str(i + 1) self.env['automatic.purchase.match'].create([{ diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index b936086a..c301f3d3 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -39,7 +39,7 @@ - + -- cgit v1.2.3 From 76a20ce3f62642cc930971659fe7645c6e52c469 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 30 Aug 2024 13:41:28 +0700 Subject: cr code voucher --- indoteknik_api/controllers/api_v1/voucher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index cd5dff20..910488d1 100644 --- a/indoteknik_api/controllers/api_v1/voucher.py +++ b/indoteknik_api/controllers/api_v1/voucher.py @@ -28,7 +28,7 @@ class Voucher(controller.Controller): domain = [] if code: visibility.append('private') - domain += [('code', '=', code)] + domain += [('code', 'ilike', code)] user_pricelist = request.env.context.get('user_pricelist') if user_pricelist: domain += [('excl_pricelist_ids', 'not in', [user_pricelist.id])] -- cgit v1.2.3 From deb05e3688af17d8bda9a53296e34b3cd8a0e963 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 30 Aug 2024 15:03:20 +0700 Subject: trying to fix flashsale --- indoteknik_api/models/product_product.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 3ecad627..386ddb6a 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -234,19 +234,17 @@ class ProductProduct(models.Model): ('pricelist_id', '=', int(product_pricelist_tier)), ('product_id', '=', self.id) ], limit=1) - if pricelist_item: - # base_price = self._get_website_price_exclude_tax() - base_price_incl = self._get_website_price_include_tax() - if tier_number in ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2']: - base_price_incl = self._v2_get_website_price_include_tax() - + base_price_incl = self._get_website_price_include_tax() + if tier_number in ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2']: + base_price_incl = self._v2_get_website_price_include_tax() + if pricelist_item and base_price_incl: discount = pricelist_item.price_discount price = base_price_incl - (base_price_incl * discount / 100) price = price / default_divide_tax price = math.floor(price) data = { - f'discount_tier{tier_number}': discount or 0, - f'price_tier{tier_number}': price or 0 + f'discount_tier{tier_number}': discount if base_price_incl else 0, + f'price_tier{tier_number}': price if base_price_incl else 0, } return data -- cgit v1.2.3 From 1e44c76fa1b4f9aa63599a4efb0adb84b3adba75 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 09:30:18 +0700 Subject: cr api get cart --- indoteknik_custom/models/website_user_cart.py | 1 + 1 file changed, 1 insertion(+) diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 0af22d47..581ed4cd 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -32,6 +32,7 @@ class WebsiteUserCart(models.Model): if self.product_id: res['cart_type'] = 'product' + res['active'] = True if self.product_id.active else False product = self.product_id.v2_api_single_response(self.product_id) res.update(product) -- cgit v1.2.3 From 6e049ba60b4ee6e20231787af3e7e3c0abcf188a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 13:26:11 +0700 Subject: add permission to button validate stock picking --- indoteknik_custom/models/stock_picking.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 6083e9e7..49f2ec80 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -354,6 +354,9 @@ class StockPicking(models.Model): def button_validate(self): + if not self.env.user.is_purchasing_manager: + raise UserError("Harus di Approve oleh Purchasing Manager") + if self._name != 'stock.picking': return super(StockPicking, self).button_validate() -- cgit v1.2.3 From b3cddd483107f9cf97c2651262d5770ba6a13d92 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 13:37:38 +0700 Subject: fix bug --- indoteknik_custom/models/stock_picking.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 49f2ec80..6083e9e7 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -354,9 +354,6 @@ class StockPicking(models.Model): def button_validate(self): - if not self.env.user.is_purchasing_manager: - raise UserError("Harus di Approve oleh Purchasing Manager") - if self._name != 'stock.picking': return super(StockPicking, self).button_validate() -- cgit v1.2.3 From 51e939b217a6ea0050cef2f5335b0dd310379b2d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 13:41:51 +0700 Subject: add permission to unreserve --- indoteknik_custom/models/stock_picking.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 6083e9e7..d16d508e 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -126,6 +126,8 @@ class StockPicking(models.Model): def do_unreserve(self): res = super(StockPicking, self).do_unreserve() + if not self.env.user.is_purchasing_manager: + raise UserError('Hanya Purchasing Manager yang bisa Unreserve') current_time = datetime.datetime.utcnow() self.date_unreserve = current_time return res -- cgit v1.2.3 From aa60fbca555f1ed654909ed11e87add53676f625 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 13:52:59 +0700 Subject: add auto sync to solr when end date h+1 --- indoteknik_custom/models/product_pricelist.py | 14 +++++++++++++- indoteknik_custom/views/product_pricelist.xml | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py index 2b17cf6e..c299ff2f 100644 --- a/indoteknik_custom/models/product_pricelist.py +++ b/indoteknik_custom/models/product_pricelist.py @@ -1,5 +1,5 @@ from odoo import models, fields -from datetime import datetime +from datetime import datetime, timedelta class ProductPricelist(models.Model): @@ -18,6 +18,18 @@ class ProductPricelist(models.Model): banner_top = fields.Binary(string='Banner Top') flashsale_tag = fields.Char(string='Flash Sale Tag') + def _check_end_date_and_update_solr(self): + today = datetime.utcnow().date() + one_day_ago = today - timedelta(days=1) + + pricelists = self.search([ + ('is_flash_sale', '=', True) + ]) + + for pricelist in pricelists: + if fields.Date.to_date(pricelist.end_date) == one_day_ago: + pricelist._constrains_related_solr_field() + def _remaining_time_in_second(self): if not self.end_date: return 0 diff --git a/indoteknik_custom/views/product_pricelist.xml b/indoteknik_custom/views/product_pricelist.xml index 0dfb69db..6eff0153 100644 --- a/indoteknik_custom/views/product_pricelist.xml +++ b/indoteknik_custom/views/product_pricelist.xml @@ -26,4 +26,18 @@ + + + + Pricelist: Check End Date and Update Solr + 1 + days + -1 + + + model._check_end_date_and_update_solr() + code + 55 + + \ No newline at end of file -- cgit v1.2.3 From 9808cae54a32a65a41d0a13a141e62d88abedfef Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 16:14:26 +0700 Subject: cr api get user cart --- indoteknik_api/controllers/api_v1/cart.py | 3 +- indoteknik_custom/models/website_user_cart.py | 110 +++++++++++++++++++------- 2 files changed, 83 insertions(+), 30 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index f472a9b0..aa47b247 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -19,7 +19,8 @@ class Cart(controller.Controller): carts.write({'source': 'add_to_cart'}) data = { 'product_total': user_cart.search_count(query), - 'products': carts.with_context(price_for="web").get_products() + 'products': carts.with_context(price_for="web").get_products(), + 'product_inactive': carts.with_context(price_for="web").get_products_inactive() } return self.response(data) diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 581ed4cd..0fd8df98 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -23,36 +23,46 @@ class WebsiteUserCart(models.Model): record.user_other_carts = others def get_product(self): - res = { - 'cart_id': self.id, - 'quantity': self.qty, - 'selected': self.is_selected, - 'can_buy': True - } - if self.product_id: - res['cart_type'] = 'product' - res['active'] = True if self.product_id.active else False - product = self.product_id.v2_api_single_response(self.product_id) - res.update(product) - - # Check if the product's inventory location is in ID 57 or 83 - target_locations = [57, 83] - stock_quant = self.env['stock.quant'].search([ - ('product_id', '=', self.product_id.id), - ('location_id', 'in', target_locations) - ]) - - if stock_quant: - res['is_in_bu'] = True - res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) - else: - res['is_in_bu'] = False - res['on_hand_qty'] = 0 + base_price = self.product_id._v2_get_website_price_include_tax() + active = self.product_id.active + if base_price > 0 and active: + res = { + 'cart_id': self.id, + 'quantity': self.qty, + 'selected': self.is_selected, + 'can_buy': True + } + res['cart_type'] = 'product' + res['active'] = True if self.product_id.active else False + product = self.product_id.v2_api_single_response(self.product_id) + res.update(product) + + # Check if the product's inventory location is in ID 57 or 83 + target_locations = [57, 83] + stock_quant = self.env['stock.quant'].search([ + ('product_id', '=', self.product_id.id), + ('location_id', 'in', target_locations) + ]) + + if stock_quant: + res['is_in_bu'] = True + res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) + else: + res['is_in_bu'] = False + res['on_hand_qty'] = 0 - flashsales = self.product_id._get_active_flash_sale() - res['has_flashsale'] = True if len(flashsales) > 0 else False + flashsales = self.product_id._get_active_flash_sale() + res['has_flashsale'] = True if len(flashsales) > 0 else False + res['subtotal'] = self.qty * res['price']['price_discount'] + return res elif self.program_line_id: + res = { + 'cart_id': self.id, + 'quantity': self.qty, + 'selected': self.is_selected, + 'can_buy': True + } res['cart_type'] = 'promotion' userdata = { 'partner_id': self.user_id.partner_id.id, @@ -63,14 +73,56 @@ class WebsiteUserCart(models.Model): if program['remaining_qty']['transaction'] < self.qty: res['can_buy'] = False - res['subtotal'] = self.qty * res['price']['price_discount'] + res['subtotal'] = self.qty * res['price']['price_discount'] - return res + return res def get_products(self): products = [x.get_product() for x in self] return products + + def get_product_inactive(self): + if self.product_id: + base_price = self.product_id._v2_get_website_price_include_tax() + active = self.product_id.active + if base_price == 0 or not active: + res = { + 'cart_id': self.id, + 'quantity': self.qty, + 'selected': self.is_selected, + 'can_buy': True + } + res['cart_type'] = 'product' + res['active'] = True if self.product_id.active else False + product = self.product_id.v2_api_single_response(self.product_id) + res.update(product) + + # Check if the product's inventory location is in ID 57 or 83 + target_locations = [57, 83] + stock_quant = self.env['stock.quant'].search([ + ('product_id', '=', self.product_id.id), + ('location_id', 'in', target_locations) + ]) + + if stock_quant: + res['is_in_bu'] = True + res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) + else: + res['is_in_bu'] = False + res['on_hand_qty'] = 0 + + flashsales = self.product_id._get_active_flash_sale() + res['has_flashsale'] = True if len(flashsales) > 0 else False + + res['subtotal'] = self.qty * res['price']['price_discount'] + + return res + + def get_products_inactive(self): + products = [x.get_product_inactive() for x in self] + + return products def get_product_by_user(self, user_id, selected=False, source=False): user_id = int(user_id) -- cgit v1.2.3 From 643b93d9b57df8916714d898ba6457282d6756c2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 08:56:07 +0700 Subject: trying to add category parent to solr product template --- indoteknik_custom/models/solr/product_template.py | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 6f76c529..2e34befe 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -101,6 +101,7 @@ class ProductTemplate(models.Model): "search_rank_i": template.search_rank, "search_rank_weekly_i": template.search_rank_weekly, "category_id_ids": category_ids, # ID kategori sebagai string yang dipisahkan koma + "category_parent_ids": self.get_category_hierarchy_ids(category_ids), # ID kategori sebagai string yang dipisahkan koma "category_name_s": ', '.join(category_names), # Nama kategori sebagai string yang dipisahkan koma "category_name": category_names, # Nama kategori sebagai list "description_t": template.website_description or '', @@ -127,6 +128,36 @@ class ProductTemplate(models.Model): if not document.get('has_price_info_b'): template._sync_price_to_solr() + def get_category_hierarchy_ids(category_id, env): + """ + Function to get category hierarchy IDs including the category itself and its parents. + + Args: + category_id (int): The ID of the category you want to retrieve. + env (Environment): The Odoo environment. + + Returns: + list: A list of IDs for the category and its parents. + """ + category_ids = [] + + def traverse_category(cat_id): + # Retrieve category object based on ID + category = env['product.category'].browse(cat_id) + + # Add the current category ID to the list + category_ids.append(category.id) + + # If there is a parent category, traverse upwards + if category.parent_id: + traverse_category(category.parent_id.id) + + # Start traversal from the initial category + traverse_category(category_id) + + # Reverse the list to get the hierarchy from top level to the current level + return list(reversed(category_ids)) + def _sync_price_to_solr(self): solr_model = self.env['apache.solr'] TIER_NUMBERS = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2'] -- cgit v1.2.3 From 8dab99ed68d5fdc3a47bcd2cd349cad1d93fd53d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 08:57:48 +0700 Subject: reverse code --- indoteknik_api/controllers/api_v1/cart.py | 3 +- indoteknik_custom/models/website_user_cart.py | 109 +++++++------------------- 2 files changed, 29 insertions(+), 83 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index aa47b247..f472a9b0 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -19,8 +19,7 @@ class Cart(controller.Controller): carts.write({'source': 'add_to_cart'}) data = { 'product_total': user_cart.search_count(query), - 'products': carts.with_context(price_for="web").get_products(), - 'product_inactive': carts.with_context(price_for="web").get_products_inactive() + 'products': carts.with_context(price_for="web").get_products() } return self.response(data) diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 0fd8df98..0af22d47 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -23,46 +23,35 @@ class WebsiteUserCart(models.Model): record.user_other_carts = others def get_product(self): + res = { + 'cart_id': self.id, + 'quantity': self.qty, + 'selected': self.is_selected, + 'can_buy': True + } + if self.product_id: - base_price = self.product_id._v2_get_website_price_include_tax() - active = self.product_id.active - if base_price > 0 and active: - res = { - 'cart_id': self.id, - 'quantity': self.qty, - 'selected': self.is_selected, - 'can_buy': True - } - res['cart_type'] = 'product' - res['active'] = True if self.product_id.active else False - product = self.product_id.v2_api_single_response(self.product_id) - res.update(product) - - # Check if the product's inventory location is in ID 57 or 83 - target_locations = [57, 83] - stock_quant = self.env['stock.quant'].search([ - ('product_id', '=', self.product_id.id), - ('location_id', 'in', target_locations) - ]) - - if stock_quant: - res['is_in_bu'] = True - res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) - else: - res['is_in_bu'] = False - res['on_hand_qty'] = 0 + res['cart_type'] = 'product' + product = self.product_id.v2_api_single_response(self.product_id) + res.update(product) + + # Check if the product's inventory location is in ID 57 or 83 + target_locations = [57, 83] + stock_quant = self.env['stock.quant'].search([ + ('product_id', '=', self.product_id.id), + ('location_id', 'in', target_locations) + ]) - flashsales = self.product_id._get_active_flash_sale() - res['has_flashsale'] = True if len(flashsales) > 0 else False - res['subtotal'] = self.qty * res['price']['price_discount'] - return res + if stock_quant: + res['is_in_bu'] = True + res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) + else: + res['is_in_bu'] = False + res['on_hand_qty'] = 0 + + 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_id': self.id, - 'quantity': self.qty, - 'selected': self.is_selected, - 'can_buy': True - } res['cart_type'] = 'promotion' userdata = { 'partner_id': self.user_id.partner_id.id, @@ -73,56 +62,14 @@ class WebsiteUserCart(models.Model): if program['remaining_qty']['transaction'] < self.qty: res['can_buy'] = False - res['subtotal'] = self.qty * res['price']['price_discount'] + res['subtotal'] = self.qty * res['price']['price_discount'] - return res + return res def get_products(self): products = [x.get_product() for x in self] return products - - def get_product_inactive(self): - if self.product_id: - base_price = self.product_id._v2_get_website_price_include_tax() - active = self.product_id.active - if base_price == 0 or not active: - res = { - 'cart_id': self.id, - 'quantity': self.qty, - 'selected': self.is_selected, - 'can_buy': True - } - res['cart_type'] = 'product' - res['active'] = True if self.product_id.active else False - product = self.product_id.v2_api_single_response(self.product_id) - res.update(product) - - # Check if the product's inventory location is in ID 57 or 83 - target_locations = [57, 83] - stock_quant = self.env['stock.quant'].search([ - ('product_id', '=', self.product_id.id), - ('location_id', 'in', target_locations) - ]) - - if stock_quant: - res['is_in_bu'] = True - res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) - else: - res['is_in_bu'] = False - res['on_hand_qty'] = 0 - - flashsales = self.product_id._get_active_flash_sale() - res['has_flashsale'] = True if len(flashsales) > 0 else False - - res['subtotal'] = self.qty * res['price']['price_discount'] - - return res - - def get_products_inactive(self): - products = [x.get_product_inactive() for x in self] - - return products def get_product_by_user(self, user_id, selected=False, source=False): user_id = int(user_id) -- cgit v1.2.3 From c9621e309e9b9db20ac01359b9369fa2d2a32024 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 09:03:29 +0700 Subject: cr solr --- indoteknik_custom/models/solr/product_template.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 2e34befe..9c5dc73e 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -128,7 +128,7 @@ class ProductTemplate(models.Model): if not document.get('has_price_info_b'): template._sync_price_to_solr() - def get_category_hierarchy_ids(category_id, env): + def get_category_hierarchy_ids(self, category_id): """ Function to get category hierarchy IDs including the category itself and its parents. @@ -143,7 +143,7 @@ class ProductTemplate(models.Model): def traverse_category(cat_id): # Retrieve category object based on ID - category = env['product.category'].browse(cat_id) + category = self.env['product.public.category'].browse(cat_id) # Add the current category ID to the list category_ids.append(category.id) -- cgit v1.2.3 From 3d70fa89180cd3318b0f952c0f628d3bb1313340 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 09:24:33 +0700 Subject: add description_clean to solr --- indoteknik_custom/models/solr/product_template.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 9c5dc73e..b5fed4fa 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -1,4 +1,5 @@ from datetime import datetime +from bs4 import BeautifulSoup from odoo import api, fields, models @@ -78,6 +79,9 @@ class ProductTemplate(models.Model): is_in_bu = bool(stock_quant) + cleaned_desc = BeautifulSoup(template.website_description or '', "html.parser").get_text() + website_description = template.website_description if cleaned_desc else '' + document = solr_model.get_doc('product', template.id) document.update({ "id": template.id, @@ -105,6 +109,7 @@ class ProductTemplate(models.Model): "category_name_s": ', '.join(category_names), # Nama kategori sebagai string yang dipisahkan koma "category_name": category_names, # Nama kategori sebagai list "description_t": template.website_description or '', + "description_clean_t": website_description or '', 'has_product_info_b': True, 'publish_b': not template.unpublished, 'sni_b': template.unpublished, -- cgit v1.2.3 From 5372bb907b3ed65f5f4de1c8f9202eb1bcb1f93e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 3 Sep 2024 09:33:24 +0700 Subject: add field promotion program line --- indoteknik_custom/models/solr/promotion_program_line.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py index 4b0e67f6..c6dbf213 100644 --- a/indoteknik_custom/models/solr/promotion_program_line.py +++ b/indoteknik_custom/models/solr/promotion_program_line.py @@ -37,6 +37,9 @@ class PromotionProgramLine(models.Model): promotion_type = rec._res_promotion_type() + # Gathering all categories + category_names = [category.name for category in rec.product_ids.product_id.public_categ_ids] + # Set sequence_i to None if rec.sequence is 0 sequence_value = None if rec.sequence == 0 else rec.sequence @@ -57,7 +60,9 @@ class PromotionProgramLine(models.Model): 'free_products_s': json.dumps(free_products), 'total_qty_i': sum([x.qty for x in rec.product_ids] + [x.qty for x in rec.free_product_ids]), 'total_qty_sold_f': [x.product_id.qty_sold for x in rec.product_ids], - 'active_b': rec.active + 'active_b': rec.active, + "manufacture_name_s": rec.product_ids.product_id.x_manufacture.display_name, + "category_name": category_names, }) self.solr().add([document]) -- cgit v1.2.3 From c617ed4000d1683a5ca9bdcf88b8ec6da6d9f8f0 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 09:35:11 +0700 Subject: fix bug description --- indoteknik_custom/models/solr/product_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index b5fed4fa..d8dec47c 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -109,7 +109,7 @@ class ProductTemplate(models.Model): "category_name_s": ', '.join(category_names), # Nama kategori sebagai string yang dipisahkan koma "category_name": category_names, # Nama kategori sebagai list "description_t": template.website_description or '', - "description_clean_t": website_description or '', + "description_clean_t": cleaned_desc or '', 'has_product_info_b': True, 'publish_b': not template.unpublished, 'sni_b': template.unpublished, -- cgit v1.2.3 From 836936b33c8206cf5344df189642e7a65f095480 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 3 Sep 2024 10:16:32 +0700 Subject: add others info in dunning run --- indoteknik_custom/models/dunning_run.py | 4 ++++ indoteknik_custom/views/dunning_run.xml | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index d75d7c51..90159cd0 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -27,6 +27,10 @@ class DunningRun(models.Model): shipper_faktur_id = fields.Many2one('delivery.carrier', string='Shipper Faktur') is_validated = fields.Boolean(string='Validated') notification = fields.Char(string='Notification') + is_paid = fields.Boolean(string='Paid') + description = fields.Char(string='Description') + comment = fields.Char(string='Comment') + def copy_date_faktur(self): if not self.is_validated: diff --git a/indoteknik_custom/views/dunning_run.xml b/indoteknik_custom/views/dunning_run.xml index 567d5e8c..dd5bb120 100644 --- a/indoteknik_custom/views/dunning_run.xml +++ b/indoteknik_custom/views/dunning_run.xml @@ -77,6 +77,13 @@ + + + + + + +
-- cgit v1.2.3 From 0b2e64dd95b42eb26c5ae92d08b176591d542a0b Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 10:17:40 +0700 Subject: cr api get user cart --- indoteknik_api/controllers/api_v1/cart.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index f472a9b0..a2fd6286 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -17,10 +17,25 @@ class Cart(controller.Controller): query = [('user_id', '=', user_id)] carts = user_cart.search(query, limit=limit, offset=offset, order='create_date desc') carts.write({'source': 'add_to_cart'}) - data = { - 'product_total': user_cart.search_count(query), - 'products': carts.with_context(price_for="web").get_products() - } + data = [] + for cart in carts: + if cart.product_id: + price = cart.product_id._v2_get_website_price_include_tax() + if cart.product_id.active and price > 0: + data.append({ + 'products': cart.with_context(price_for="web").get_products() + }) + else: + data.append({ + 'product_inactive': cart.with_context(price_for="web").get_products() + }) + else: + data.append({ + 'products': cart.with_context(price_for="web").get_products() + }) + data.append({ + 'product_total': user_cart.search_count(query) + }) return self.response(data) @http.route(PREFIX_USER + 'cart/count', auth='public', methods=['GET', 'OPTIONS']) -- cgit v1.2.3 From 857567b0d10c5888e20646b7258cc13f0cedfdd2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 10:25:46 +0700 Subject: reverse code --- indoteknik_api/controllers/api_v1/cart.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index a2fd6286..f472a9b0 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -17,25 +17,10 @@ class Cart(controller.Controller): query = [('user_id', '=', user_id)] carts = user_cart.search(query, limit=limit, offset=offset, order='create_date desc') carts.write({'source': 'add_to_cart'}) - data = [] - for cart in carts: - if cart.product_id: - price = cart.product_id._v2_get_website_price_include_tax() - if cart.product_id.active and price > 0: - data.append({ - 'products': cart.with_context(price_for="web").get_products() - }) - else: - data.append({ - 'product_inactive': cart.with_context(price_for="web").get_products() - }) - else: - data.append({ - 'products': cart.with_context(price_for="web").get_products() - }) - data.append({ - 'product_total': user_cart.search_count(query) - }) + data = { + 'product_total': user_cart.search_count(query), + 'products': carts.with_context(price_for="web").get_products() + } return self.response(data) @http.route(PREFIX_USER + 'cart/count', auth='public', methods=['GET', 'OPTIONS']) -- cgit v1.2.3 From 51face2a473c347e338650d059445dc4f085d96e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 3 Sep 2024 13:19:42 +0700 Subject: update field --- indoteknik_custom/models/solr/promotion_program_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py index c6dbf213..3e3a2a28 100644 --- a/indoteknik_custom/models/solr/promotion_program_line.py +++ b/indoteknik_custom/models/solr/promotion_program_line.py @@ -61,7 +61,7 @@ class PromotionProgramLine(models.Model): 'total_qty_i': sum([x.qty for x in rec.product_ids] + [x.qty for x in rec.free_product_ids]), 'total_qty_sold_f': [x.product_id.qty_sold for x in rec.product_ids], 'active_b': rec.active, - "manufacture_name_s": rec.product_ids.product_id.x_manufacture.display_name, + "manufacture_name_s": rec.product_ids.product_id.x_manufacture.x_name or '', "category_name": category_names, }) -- cgit v1.2.3 From eced81efba75d710d164f1baa2d2e50b4d2d3c18 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 14:14:40 +0700 Subject: fix bug --- indoteknik_api/controllers/api_v1/sale_order.py | 7 ++++++- indoteknik_custom/models/sale_order.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 1b7c1af4..c871b69e 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -460,11 +460,16 @@ class SaleOrder(controller.Controller): sale_order.apply_promotion_program() voucher_code = params['value']['voucher'] - voucher = request.env['voucher'].search([('code', '=', voucher_code)]) + voucher = request.env['voucher'].search([('code', '=', voucher_code),('apply_type', 'in', ['all', 'brand'])], limit=1) + voucher_shipping = request.env['voucher'].search([('code', '=', voucher_code),('apply_type', 'in', ['shipping'])], limit=1) if voucher and len(promotions) == 0: sale_order.voucher_id = voucher.id sale_order.apply_voucher() + if voucher_shipping and len(promotions) == 0: + sale_order.voucher_shipping_id = voucher_shipping.id + sale_order.apply_voucher() + cart_ids = [x['cart_id'] for x in carts] if sale_order._requires_approval_margin_leader(): #jika ada error tambahkan kondisi if params['value']['type'] == 'sale_order': sale_order.approval_status = 'pengajuan2' diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 710e99de..348ea4d3 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -109,6 +109,7 @@ class SaleOrder(models.Model): date_driver_departure = fields.Datetime(string='Departure Date', compute='_compute_date_kirim', copy=False) note_website = fields.Char(string="Note Website") use_button = fields.Boolean(string='Using Calculate Selling Price', copy=False) + voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Voucher', copy=False) def _compute_date_kirim(self): for rec in self: -- cgit v1.2.3 From 0222d907c08ef27dd8d3b303b55d70542cbeb788 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 4 Sep 2024 10:14:54 +0700 Subject: cr api cart v1 --- indoteknik_api/controllers/api_v1/cart.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index f472a9b0..6bbb812c 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -17,9 +17,27 @@ class Cart(controller.Controller): query = [('user_id', '=', user_id)] carts = user_cart.search(query, limit=limit, offset=offset, order='create_date desc') carts.write({'source': 'add_to_cart'}) + products = [] + products_inactive = [] + for cart in carts: + if cart.product_id: + price = cart.product_id._v2_get_website_price_include_tax() + if cart.product_id.active and price > 0: + product = cart.with_context(price_for="web").get_products() + for product_active in product: + products.append(product_active) + else: + product_inactives = cart.with_context(price_for="web").get_products() + for inactives in product_inactives: + products_inactive.append(inactives) + else: + program = cart.with_context(price_for="web").get_products() + for programs in program: + products.append(programs) data = { 'product_total': user_cart.search_count(query), - 'products': carts.with_context(price_for="web").get_products() + 'products': products, + 'products_inactive': products_inactive } return self.response(data) -- cgit v1.2.3 From ca5c12f1ee40ea3c34cafcc9fe73d3d79a6a5b98 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 4 Sep 2024 15:53:40 +0700 Subject: fix margin with fee third party --- indoteknik_custom/models/sale_order.py | 2 +- indoteknik_custom/views/sale_order.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 348ea4d3..81c3f5ed 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -744,7 +744,7 @@ class SaleOrder(models.Model): delivery_amt = order.delivery_amt else: delivery_amt = 0 - order.total_percent_margin = round((order.total_margin / (order.amount_untaxed-delivery_amt)) * 100, 2) + order.total_percent_margin = round((order.total_margin / (order.amount_untaxed-delivery_amt-order.fee_third_party)) * 100, 2) # order.total_percent_margin = round((order.total_margin / (order.amount_untaxed)) * 100, 2) @api.onchange('sales_tax_id') diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 1257ff85..a351607f 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -112,6 +112,7 @@ "/> + -- cgit v1.2.3 From 1bb074bb8f63072fb990c57c18986c50981f1402 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 4 Sep 2024 17:12:38 +0700 Subject: fix voucher shipping --- indoteknik_api/controllers/api_v1/sale_order.py | 4 +- indoteknik_custom/models/sale_order.py | 54 ++++++++++++++++++++++++- indoteknik_custom/models/website_user_cart.py | 3 +- indoteknik_custom/views/sale_order.xml | 16 ++++++++ 4 files changed, 72 insertions(+), 5 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index c871b69e..e8d18366 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -407,7 +407,7 @@ class SaleOrder(controller.Controller): 'real_invoice_id': params['value']['partner_invoice_id'], 'partner_purchase_order_name': params['value']['po_number'], 'partner_purchase_order_file': params['value']['po_file'], - 'delivery_amt': params['value']['delivery_amount'], + 'delivery_amt': params['value']['delivery_amount'] * 1.10, 'estimated_arrival_days': params['value']['estimated_arrival_days'], 'shipping_cost_covered': 'customer', 'shipping_paid_by': 'customer', @@ -468,7 +468,7 @@ class SaleOrder(controller.Controller): if voucher_shipping and len(promotions) == 0: sale_order.voucher_shipping_id = voucher_shipping.id - sale_order.apply_voucher() + sale_order.apply_voucher_shipping() cart_ids = [x['cart_id'] for x in carts] if sale_order._requires_approval_margin_leader(): #jika ada error tambahkan kondisi if params['value']['type'] == 'sale_order': diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 348ea4d3..0268f27b 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -88,6 +88,8 @@ class SaleOrder(models.Model): voucher_id = fields.Many2one(comodel_name='voucher', string='Voucher', copy=False) applied_voucher_id = fields.Many2one(comodel_name='voucher', string='Applied Voucher', copy=False) amount_voucher_disc = fields.Float(string='Voucher Discount') + applied_voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Applied Voucher', copy=False) + amount_voucher_shipping_disc = fields.Float(string='Voucher Discount') source_id = fields.Many2one('utm.source', 'Source', domain="[('id', 'in', [32, 59, 60, 61])]", required=True) estimated_arrival_days = fields.Integer('Estimated Arrival Days', default=0) email = fields.Char(string='Email') @@ -109,7 +111,7 @@ class SaleOrder(models.Model): date_driver_departure = fields.Datetime(string='Departure Date', compute='_compute_date_kirim', copy=False) note_website = fields.Char(string="Note Website") use_button = fields.Boolean(string='Using Calculate Selling Price', copy=False) - voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Voucher', copy=False) + voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Voucher Shipping', copy=False) def _compute_date_kirim(self): for rec in self: @@ -781,6 +783,28 @@ class SaleOrder(models.Model): self.apply_voucher() + def action_apply_voucher_shipping(self): + for line in self.order_line: + if line.order_promotion_id: + raise UserError('Voucher tidak dapat digabung dengan promotion program') + + voucher = self.voucher_shipping_id + if voucher.limit > 0 and voucher.count_order >= voucher.limit: + raise UserError('Voucher tidak dapat digunakan karena sudah habis digunakan') + + partner_voucher_orders = [] + for order in voucher.order_ids: + if order.partner_id.id == self.partner_id.id: + partner_voucher_orders.append(order) + + if voucher.limit_user > 0 and len(partner_voucher_orders) >= voucher.limit_user: + raise UserError('Voucher tidak dapat digunakan karena Customer ini sudah menghabiskan kuota voucher') + + if self.pricelist_id.id in [x.id for x in voucher.excl_pricelist_ids]: + raise UserError('Voucher tidak dapat digunakan karena pricelist ini tidak berlaku pada voucher') + + self.apply_voucher_shipping() + def apply_voucher(self): order_line = [] for line in self.order_line: @@ -822,6 +846,29 @@ class SaleOrder(models.Model): self.amount_voucher_disc = voucher['discount']['all'] self.applied_voucher_id = self.voucher_id + def apply_voucher_shipping(self): + for order in self: + delivery_amt = order.delivery_amt + voucher = order.voucher_shipping_id + + if voucher: + max_discount_amount = voucher.discount_amount + voucher_type = voucher.discount_type + + if voucher_type == 'fixed_price': + discount = max_discount_amount + elif voucher_type == 'percentage': + discount = delivery_amt * (max_discount_amount / 100) + + delivery_amt -= discount + + delivery_amt = max(delivery_amt, 0) + + order.delivery_amt = delivery_amt + + order.amount_voucher_shipping_disc = discount + order.applied_voucher_shipping_id = order.voucher_id.id + def cancel_voucher(self): self.applied_voucher_id = False self.amount_voucher_disc = 0 @@ -830,6 +877,11 @@ class SaleOrder(models.Model): line.discount = line.initial_discount line.initial_discount = False + def cancel_voucher_shipping(self): + self.delivery_amt + self.amount_voucher_shipping_disc + self.applied_voucher_shipping_id = False + self.amount_voucher_shipping_disc = 0 + def action_web_approve(self): if self.env.uid != self.partner_id.user_id.id: raise UserError('You are not authorized to approve this order. Only %s can approve this order.' % self.partner_id.user_id.name) diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 0af22d47..b0cf47f7 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -130,8 +130,7 @@ class WebsiteUserCart(models.Model): if voucher_shipping: voucher_shipping_info = voucher_shipping.apply(order_line) - discount_voucher_shipping = voucher_shipping_info['discount']['all'] - subtotal -= discount_voucher_shipping + discount_voucher_shipping = voucher_shipping_info['discount']['all'] tax = round(subtotal * 0.11) grand_total = subtotal + tax diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 1257ff85..44070f35 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -43,6 +43,17 @@ attrs="{'invisible': ['|', ('applied_voucher_id', '=', False), ('state', 'not in', ['draft','sent'])]}" />
+