summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2024-03-12 02:49:52 +0000
committerIT Fixcomart <it@fixcomart.co.id>2024-03-12 02:49:52 +0000
commit8899771cb6e4d39752a506e7aa95e5e388ff3a9f (patch)
treef436cda35f861b8017823fe36e674fe5687d4fbb
parent29dfec334ebf6a15a8a66e4af564fd5d812d8d67 (diff)
parent41056a3fcf9cf80ac3609ab32223ffbac5b3ad83 (diff)
Merged in production (pull request #135)
Production
-rw-r--r--indoteknik_custom/models/price_group.py16
-rw-r--r--indoteknik_custom/models/promotion/promotion_program_line.py4
-rwxr-xr-xindoteknik_custom/models/purchase_pricelist.py55
-rw-r--r--indoteknik_custom/models/website_user_cart.py3
-rwxr-xr-xindoteknik_custom/views/purchase_pricelist.xml8
5 files changed, 68 insertions, 18 deletions
diff --git a/indoteknik_custom/models/price_group.py b/indoteknik_custom/models/price_group.py
index 2a1bbc91..1b1c817f 100644
--- a/indoteknik_custom/models/price_group.py
+++ b/indoteknik_custom/models/price_group.py
@@ -19,6 +19,22 @@ class PriceGroup(models.Model):
group7 = fields.Float(string='Kelompok 7 (%)')
group8 = fields.Float(string='Kelompok 8 (%)')
+ def collect_price_group(self):
+ PRICE_GROUP_ID = {
+ 'markup': 1,
+ 'tier_1': 2,
+ 'tier_2': 3,
+ 'tier_3': 4,
+ 'tier_4': 5,
+ 'tier_5': 6,
+ }
+
+ result = {}
+ for key in PRICE_GROUP_ID:
+ result[key] = self.env['price.group'].browse(PRICE_GROUP_ID[key])
+
+ return result
+
class Manufacture(models.Model):
_inherit = 'x_manufactures'
diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py
index cb231889..4bf50ac9 100644
--- a/indoteknik_custom/models/promotion/promotion_program_line.py
+++ b/indoteknik_custom/models/promotion/promotion_program_line.py
@@ -101,8 +101,8 @@ class PromotionProgramLine(models.Model):
weight = sum(x['package_weight'] for x in merged_products)
# Sum of products and free products in 1 package quantity
- products_total = sum(x['price']['price_discount'] * x['qty'] / qty for x in products)
- free_products_total = sum(x['price']['price_discount'] * x['qty'] / qty for x in free_products)
+ products_total = sum(x['price']['price'] * x['qty'] / qty for x in products)
+ free_products_total = sum(x['price']['price'] * x['qty'] / qty for x in free_products)
package_price = products_total + free_products_total
response = {
diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py
index e7a04927..309beab7 100755
--- a/indoteknik_custom/models/purchase_pricelist.py
+++ b/indoteknik_custom/models/purchase_pricelist.py
@@ -34,23 +34,14 @@ class PurchasePricelist(models.Model):
self.human_last_update = current_time
@api.constrains('system_last_update','system_price','product_price','human_last_update','taxes_system_id','taxes_product_id')
- def _contrains_include_price(self):
-
- price_unit, taxes = self._get_valid_price()
- if price_unit == 0:
- self.include_price = 0
- return
+ def _constrains_include_price(self):
+ price, taxes = self._get_valid_price()
- tax_include = taxes.price_include
- if taxes:
- if tax_include:
- price_unit = price_unit
- else:
- price_unit = price_unit + (price_unit * 11 / 100)
- else:
- price_unit = price_unit + (price_unit * 11 / 100)
+ # When have tax is excluded or empty tax, then multiply by 1.11
+ if (taxes and not taxes.price_include) or not taxes:
+ price *= 1.11
- self.include_price = price_unit
+ self.include_price = price
def _get_valid_price(self):
purchase_price = self
@@ -81,4 +72,36 @@ class PurchasePricelist(models.Model):
massage="Ada duplikat product dan vendor, berikut data yang anda duplikat : \n" + str(existing_purchase.product_id.name) + " - " + str(existing_purchase.vendor_id.name) + " - " + str(existing_purchase.product_price)
if existing_purchase:
raise UserError(massage)
- \ No newline at end of file
+
+ def action_calculate_pricelist(self):
+ MAX_PRICELIST = 10
+ active_ids = self.env.context.get('active_ids', [])
+
+ if len(active_ids) > MAX_PRICELIST:
+ raise ValidationError(_('You can only calculate up to %s pricelists at a time.' % MAX_PRICELIST))
+
+ records = self.env['purchase.pricelist'].browse(active_ids)
+ price_group = self.env['price.group'].collect_price_group()
+ for rec in records:
+ product_group = rec.product_id.product_tmpl_id.x_manufacture.pricing_group or None
+ price_incl = rec.include_price
+
+ markup_percentage = price_group['markup'][product_group]
+ if markup_percentage == 0: continue
+
+ product_domain = [('product_id', '=', rec.product_id.id)]
+ markup_pricelist = price_group['markup'].pricelist_id
+ base_price = price_incl + (price_incl * markup_percentage / 100)
+ base_prod_pricelist = self.env['product.pricelist.item'].search(product_domain + [('pricelist_id', '=', markup_pricelist.id)], limit=1)
+ base_prod_pricelist.fixed_price = base_price
+
+ tier_percentages = [price_group[f'tier_{i}'][product_group] for i in range(1, 6)]
+ for i, tier_percentage in enumerate(tier_percentages):
+ tier_pricelist = price_group[f'tier_{i + 1}'].pricelist_id
+ tier_price = price_incl + (price_incl * tier_percentage / 100)
+ tier_perc = (base_price - tier_price) / base_price * 100
+ tier_prod_pricelist = self.env['product.pricelist.item'].search(product_domain + [('pricelist_id', '=', tier_pricelist.id)], limit=1)
+ tier_prod_pricelist.price_discount = tier_perc
+
+ rec.product_id.product_tmpl_id._create_solr_queue('_sync_price_to_solr')
+ \ No newline at end of file
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index eaa5f009..bbff6035 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -96,6 +96,9 @@ class WebsiteUserCart(models.Model):
if voucher:
order_line = []
for product in products:
+ if product['cart_type'] == 'promotion':
+ continue
+
order_line.append({
'product_id': self.env['product.product'].browse(product['id']),
'price': product['price']['price'],
diff --git a/indoteknik_custom/views/purchase_pricelist.xml b/indoteknik_custom/views/purchase_pricelist.xml
index 889fe2e0..5d8b84d6 100755
--- a/indoteknik_custom/views/purchase_pricelist.xml
+++ b/indoteknik_custom/views/purchase_pricelist.xml
@@ -60,6 +60,14 @@
</field>
</record>
+ <record id="ir_actions_server_purchase_pricelist_calculate_pricelist" model="ir.actions.server">
+ <field name="name">Calculate Pricelist</field>
+ <field name="model_id" ref="indoteknik_custom.model_purchase_pricelist"/>
+ <field name="binding_model_id" ref="indoteknik_custom.model_purchase_pricelist"/>
+ <field name="state">code</field>
+ <field name="code">model.action_calculate_pricelist()</field>
+ </record>
+
<menuitem
id="menu_purchase_pricelist"
name="Purchase Pricelist"