From 5614f5f0fa0322089f17feeeeeb56af93bf76670 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 5 Oct 2023 11:08:16 +0700 Subject: mandatory email --- indoteknik_custom/models/sale_order.py | 8 +++++--- indoteknik_custom/views/sale_order.xml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index e201496a..93c63d56 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -392,9 +392,11 @@ class SaleOrder(models.Model): def _set_sppkp_npwp_contact(self): partner = self.partner_id.parent_id or self.partner_id - partner.customer_type = self.customer_type - partner.npwp = self.npwp - partner.sppkp = self.sppkp + if not partner.sppkp or not partner.npwp or not partner.email or partner.customer_type: + partner.customer_type = self.customer_type + partner.npwp = self.npwp + partner.sppkp = self.sppkp + partner.email = self.email def _compute_total_margin(self): for order in self: diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 0d972ec1..e0e9ac54 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -48,7 +48,7 @@ - + -- cgit v1.2.3 From c6c1e26d35327b61a88b247ef94cfff9257b492a Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 5 Oct 2023 16:48:43 +0700 Subject: Add computed_price field on product pricelist --- indoteknik_custom/models/product_pricelist.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py index 026977f8..144b8689 100644 --- a/indoteknik_custom/models/product_pricelist.py +++ b/indoteknik_custom/models/product_pricelist.py @@ -40,5 +40,4 @@ class ProductPricelistItem(models.Model): _inherit = 'product.pricelist.item' manufacture_id = fields.Many2one('x_manufactures', string='Manufacture') - - \ No newline at end of file + computed_price = fields.Float(string='Computed Price') \ No newline at end of file -- cgit v1.2.3 From 2fa15330d221cb68e5b9acdb4379aa82764f46f0 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 6 Oct 2023 11:17:53 +0700 Subject: Update flashsale calculation price for web and odoo --- indoteknik_api/controllers/api_v1/sale_order.py | 12 +++++------- indoteknik_api/models/product_product.py | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index b17c2231..8209c751 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -302,18 +302,19 @@ class SaleOrder(controller.Controller): source = params['value']['source'] carts = user_cart.get_product_by_user(user_id=user_id, selected=True, source=source) - order_lines = [] promotions = [] for cart in carts: if cart['cart_type'] == 'product': - order_lines.append({ + order_line = request.env['sale.order.line'].create({ 'company_id': 1, 'order_id': sale_order.id, - 'price_unit': cart['price']['price'], - 'discount': cart['price']['discount_percentage'], 'product_id': cart['id'], 'product_uom_qty': cart['quantity'] }) + order_line.product_id_change() + order_line.onchange_vendor_id() + order_line.price_unit = cart['price']['price'] + order_line.discount = cart['price']['discount_percentage'] elif cart['cart_type'] == 'promotion': promotions.append({ 'order_id': sale_order.id, @@ -321,9 +322,6 @@ class SaleOrder(controller.Controller): 'quantity': cart['quantity'] }) - lines = request.env['sale.order.line'].create(order_lines) - for line in lines: - line.product_id_change() request.env['sale.order.promotion'].create(promotions) if len(promotions) > 0: diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index bcba8cfc..d370e52b 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -251,6 +251,7 @@ class ProductProduct(models.Model): return data def _get_flashsale_price(self): + price_for = self.env.context.get('price_for', 'odoo') result = {} current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') @@ -264,7 +265,16 @@ class ProductProduct(models.Model): if not item: return result - base_price = self._v2_get_website_price_exclude_tax() + tier1_id = self.env['ir.config_parameter'].get_param('product.pricelist.tier1_v2', 0) + base_pricelist = self.env['product.pricelist.item'].search([ + ('pricelist_id', '=', int(tier1_id)), + ('product_id', '=', self.id) + ], limit=1) + + base_price = 0 + if base_pricelist: + base_price = base_pricelist.computed_price + discount = 0 price_flashsale = 0 if item.price_discount > 0: @@ -274,6 +284,10 @@ class ProductProduct(models.Model): price_flashsale = item.fixed_price # ask darren for include or exclude discount = (base_price - price_flashsale) // base_price * 100 + if price_for == 'odoo': + base_price = self._v2_get_website_price_include_tax() + discount = (base_price - price_flashsale) / base_price * 100 + jkt_tz = pytz.timezone('Asia/Jakarta') result.update({ 'flashsale_id': item.pricelist_id.id, -- cgit v1.2.3