diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2023-09-29 02:32:56 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2023-09-29 02:32:56 +0000 |
| commit | 78f205302c35cab2512971d64c8152aab2dcfa95 (patch) | |
| tree | 72be75ad949fe9efaf7b55c8f7f5722225538b28 /indoteknik_custom/models/product_template.py | |
| parent | 50b5bd7bd984ef108e8bd324440050a222d8262f (diff) | |
| parent | 0bb47005022b33c79ecfb5924d41f35ce794c5fb (diff) | |
Merged in production (pull request #126)
Production
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 86 |
1 files changed, 55 insertions, 31 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 4c11dcef..d35188b4 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -1,5 +1,5 @@ from odoo import fields, models, api -from datetime import datetime, timedelta +from datetime import datetime, timedelta, date from odoo.exceptions import UserError import logging import requests @@ -52,11 +52,30 @@ class ProductTemplate(models.Model): help='Centang jika ingin ditammpilkan di website sebagai segment Produk Baru') seq_new_product = fields.Integer(string='Seq New Product', help='Urutan Sequence New Product') is_edited = fields.Boolean(string='Is Edited') + publish = fields.Boolean(string='Publish', default=True) + + @api.constrains('active') + def constrains_active_publish(self): + if not self.active or self.type != 'product': + self.publish = False + else: + self.publish = True + + self._create_solr_queue('_sync_product_template_to_solr') + + def day_product_to_edit(self): + day_products = [] + + for product in self: + day_product = (product.write_date - product.create_date).days + day_products.append(day_product) + + return day_products @api.constrains('name', 'default_code') def _check_duplicate_product(self): for product in self: - if not self.env.user.is_purchasing_manager: + if not self.env.user.is_purchasing_manager and not self.env.user.is_editor_product: domain = [('default_code', '!=', False)] if product.product_variant_ids: @@ -76,22 +95,21 @@ class ProductTemplate(models.Model): if product.write_date == product.create_date: message = "SKU atau Name yang Anda gunakan sudah digunakan di produk lain" - else: + elif all(day_product > 0 for day_product in product.day_product_to_edit()): domain = [('id', '=', product.id)] message = "Hanya Pak Tyas yang dapat merubah data produk" - existing_purchase = self.search(domain, limit=1) - if existing_purchase: raise UserError(message) @api.constrains('name') def _validate_name(self): - pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/%-]+$' + rule_regex = self.env['ir.config_parameter'].sudo().get_param('product.product.rule_name_regex') or '' + pattern = rf'^{rule_regex}$' if not re.match(pattern, self.name): - pattern_suggest = r'[a-zA-Z0-9\[\]\(\)\.\s/%-]+' + pattern_suggest = rf"{rule_regex}" suggest = ''.join(re.findall(pattern_suggest, self.name)) - raise UserError(f'Nama hanya bisa menggunakan angka, strip, huruf kecil, huruf besar, titik, kurung lengkung, kurung siku, garis miring. Contoh: {suggest}') + raise UserError(f'Contoh yang benar adalah {suggest}') # def write(self, vals): # if 'solr_flag' not in vals and self.solr_flag == 1: @@ -175,13 +193,7 @@ class ProductTemplate(models.Model): def _compute_web_price(self): for template in self: - # product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) - - product_pricelist_item = self.env['product.pricelist.item'].search([ - ('pricelist_id', '=', 1), - ('product_id', '=', template.product_variant_id.id)], limit=1) - price = product_pricelist_item.fixed_price - template.web_price = price + template.web_price = template.product_variant_ids[0].web_price def _have_promotion_program(self): for template in self: @@ -324,10 +336,19 @@ class ProductProduct(models.Model): sla_version = fields.Integer(string="SLA Version", default=0) is_edited = fields.Boolean(string='Is Edited') + def day_product_to_edit(self): + day_products = [] + + for product in self: + day_product = (product.write_date - product.create_date).days + day_products.append(day_product) + + return day_products + @api.constrains('name','default_code') def _check_duplicate_product(self): - if not self.env.user.is_purchasing_manager: - for product in self: + for product in self: + if not self.env.user.is_purchasing_manager and not self.env.user.is_editor_product: if product.write_date == product.create_date: domain = [ ('default_code', '!=', False), @@ -340,25 +361,20 @@ class ProductProduct(models.Model): existing_purchase = self.search(domain, limit=1) if existing_purchase: raise UserError(massage) - else: - domain = [ - ('id', '=', product.id), - ('is_edited', '=', True), - ] + elif all(day_product > 0 for day_product in product.day_product_to_edit()): + domain = [('id', '=', product.id)] existing_purchase = self.search(domain) if existing_purchase: raise UserError('Hanya Pak Tyas Yang Dapat Merubah Data Product') - if not existing_purchase: - true = True - self.is_edited = true - + @api.constrains('name') def _validate_name(self): - pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/%-]+$' + rule_regex = self.env['ir.config_parameter'].sudo().get_param('product.product.rule_name_regex') or '' + pattern = rf'^{rule_regex}$' if not re.match(pattern, self.name): - pattern_suggest = r'[a-zA-Z0-9\[\]\(\)\.\s/%-]+' + pattern_suggest = rf"{rule_regex}" suggest = ''.join(re.findall(pattern_suggest, self.name)) - raise UserError(f'Nama hanya bisa menggunakan angka, strip, huruf kecil, huruf besar, titik, kurung lengkung, kurung siku, garis miring. Contoh: {suggest}') + raise UserError(f'Contoh yang benar adalah {suggest}') def _get_qty_incoming_bandengan(self): for product in self: @@ -389,8 +405,16 @@ class ProductProduct(models.Model): def _compute_web_price(self): for product in self: - product_pricelist_item = self.env['product.pricelist.item'].search( - [('pricelist_id', '=', 1), ('product_id', '=', product.id)], limit=1) + pricelist_id = self.env.context.get('pricelist') + + domain = [('pricelist_id', '=', pricelist_id or 1), ('product_id', '=', product.id)] + product_pricelist_item = self.env['product.pricelist.item'].search(domain, limit=1) + + if product_pricelist_item.base_pricelist_id: + base_pricelist_id = product_pricelist_item.base_pricelist_id.id + domain = [('pricelist_id', '=', base_pricelist_id), ('product_id', '=', product.id)] + product_pricelist_item = self.env['product.pricelist.item'].search(domain, limit=1) + product.web_price = product_pricelist_item.fixed_price def _compute_stock_vendor(self): |
