summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-10-06 11:20:29 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-10-06 11:20:29 +0700
commit68f40590264422af29fff425f1f7664283faa540 (patch)
tree0139db5bc9605080a38e23ed8733cf423b4b9657
parent894a85b193dcd1e4044921f0c8be5ccfaa04900a (diff)
parent2fa15330d221cb68e5b9acdb4379aa82764f46f0 (diff)
Merge branch 'change/feature/pricelist' into dev/pricelist
-rw-r--r--indoteknik_api/controllers/api_v1/sale_order.py12
-rw-r--r--indoteknik_api/models/product_product.py16
-rw-r--r--indoteknik_custom/models/product_pricelist.py3
-rwxr-xr-xindoteknik_custom/models/sale_order.py8
-rwxr-xr-xindoteknik_custom/views/sale_order.xml2
5 files changed, 27 insertions, 14 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,
diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py
index 384d1353..b7a6d77e 100644
--- a/indoteknik_custom/models/product_pricelist.py
+++ b/indoteknik_custom/models/product_pricelist.py
@@ -45,5 +45,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
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 728c0bba..9324930e 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 @@
<field name="customer_type" attrs="{'required': ['|', ('create_date', '&gt;', '2023-06-28'), ('create_date', '=', False)]}"/>
<field name="npwp" placeholder='99.999.999.9-999.999' attrs="{'required': ['|', ('create_date', '&gt;', '2023-06-28'), ('create_date', '=', False)]}"/>
<field name="sppkp" attrs="{'invisible': [('customer_type','!=','pkp')], 'required': [('customer_type', '=', 'pkp')]}"/>
- <field name="email" attrs="{'required': [('create_date', '&gt;', '2023-09-28')]}"/>
+ <field name="email" required="1"/>
<field name="due_id" readonly="1"/>
<field name="source_id" domain="[('id', 'in', [32, 59, 60, 61])]" attrs="{'required':[('create_date', '&gt;', '2023-09-10')]}"/>
</field>