diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2024-03-12 02:49:52 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2024-03-12 02:49:52 +0000 |
| commit | 8899771cb6e4d39752a506e7aa95e5e388ff3a9f (patch) | |
| tree | f436cda35f861b8017823fe36e674fe5687d4fbb /indoteknik_custom/models/purchase_pricelist.py | |
| parent | 29dfec334ebf6a15a8a66e4af564fd5d812d8d67 (diff) | |
| parent | 41056a3fcf9cf80ac3609ab32223ffbac5b3ad83 (diff) | |
Merged in production (pull request #135)
Production
Diffstat (limited to 'indoteknik_custom/models/purchase_pricelist.py')
| -rwxr-xr-x | indoteknik_custom/models/purchase_pricelist.py | 55 |
1 files changed, 39 insertions, 16 deletions
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 |
