diff options
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 152 |
1 files changed, 84 insertions, 68 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 7ec5a002..d2fa793a 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -74,32 +74,34 @@ class ProductTemplate(models.Model): @api.constrains('name', 'default_code') def _check_duplicate_product(self): for product in self: - 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: - domain.extend([ - '|', - ('name', 'in', [variants.name for variants in product.product_variant_ids]), - ('default_code', 'in', [variants.default_code for variants in product.product_variant_ids]) - ]) - else: - domain.extend([ - '|', - ('name', 'in', [product.name]), - ('default_code', 'in', [product.default_code]) - ]) - - domain.append(('id', '!=', product.id)) - - if product.write_date == product.create_date: - message = "SKU atau Name yang Anda gunakan sudah digunakan di produk lain" - 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) + if self.env.user.is_purchasing_manager or self.env.user.is_editor_product or self.env.user.id in [1, 25]: + continue + + domain = [('default_code', '!=', False)] + + if product.product_variant_ids: + domain.extend([ + '|', + ('name', 'in', [variants.name for variants in product.product_variant_ids]), + ('default_code', 'in', [variants.default_code for variants in product.product_variant_ids]) + ]) + else: + domain.extend([ + '|', + ('name', 'in', [product.name]), + ('default_code', 'in', [product.default_code]) + ]) + + domain.append(('id', '!=', product.id)) + + if product.write_date == product.create_date: + message = "SKU atau Name yang Anda gunakan sudah digunakan di produk lain" + elif all(day_product > 0 for day_product in product.day_product_to_edit()): + domain = [('id', '=', product.id)] + message = "Anda tidak berhak merubah data produk ini" + existing_purchase = self.search(domain, limit=1) + if existing_purchase: + raise UserError(message) @api.constrains('name') def _validate_name(self): @@ -157,28 +159,34 @@ class ProductTemplate(models.Model): _logger.info('Updated New Product %s' % product.name) def update_internal_reference(self, limit=100): - templates_without_variant = self.env['product.template'].search([ - ('default_code', '=', False), - ('type', '=', 'product'), - ('active', '=', True), - ('product_variant_ids', '=', False), - ], limit=limit) - for template_without_variant in templates_without_variant: - template_without_variant.default_code = 'IT.'+str(template_without_variant.id) - _logger.info('Updated Template %s' % template_without_variant.name) - - templates_with_variant = self.env['product.template'].search([ + templates = self.env['product.template'].search([ ('default_code', '=', False), + ('product_variant_ids.default_code', '=', False), ('type', '=', 'product'), - ('active', '=', True), - ('product_variant_ids', '!=', False), - ], limit=limit) - for template_with_variant in templates_with_variant: - for product in template_with_variant.product_variant_ids: - if product.default_code: - continue - product.default_code = 'ITV.'+str(product.id) - _logger.info('Updated Variant %s' % product.name) + ('active', '=', True) + ], limit=limit, order='write_date desc') + for template in templates: + if not template.default_code: + template.default_code = 'IT.'+str(template.id) + + for variant in template.product_variant_ids: + if not variant.default_code: + variant.default_code = 'ITV.%s' % str(variant.id) + + _logger.info('Updated Template %s' % template.name) + + # templates_with_variant = self.env['product.product'].search([ + # ('default_code', '=', False), + # ('type', '=', 'product'), + # ('active', '=', True), + # ('product_tmpl_id', '!=', False), + # ], limit=limit, order='write_date desc') + # for template_with_variant in templates_with_variant: + # for product in template_with_variant.product_variant_ids: + # if product.default_code: + # continue + # product.default_code = 'ITV.'+str(product.id) + # _logger.info('Updated Variant %s' % product.name) @api.onchange('name','default_code','x_manufacture','product_rating','website_description','image_1920','weight','public_categ_ids') def update_solr_flag(self): @@ -339,10 +347,11 @@ class ProductProduct(models.Model): usage = fields.Char(string='Usage') specification = fields.Char(string='Specification') material = fields.Char(string='Material') - qty_onhand_bandengan = fields.Float(string='Qty Onhand Bandengan', compute='_get_qty_onhand_bandengan') - qty_incoming_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_incoming_bandengan') - qty_outgoing_bandengan = fields.Float(string='Qty Outgoing Bandengan', compute='_get_qty_outgoing_bandengan') - qty_available_bandengan = fields.Float(string='Qty Available Bandengan', compute='_get_qty_available_bandengan') + qty_onhand_bandengan = fields.Float(string='Onhand BU', compute='_get_qty_onhand_bandengan') + qty_incoming_bandengan = fields.Float(string='Incoming BU', compute='_get_qty_incoming_bandengan') + qty_outgoing_bandengan = fields.Float(string='Outgoing BU', compute='_get_qty_outgoing_bandengan') + qty_available_bandengan = fields.Float(string='Available BU', compute='_get_qty_available_bandengan') + qty_free_bandengan = fields.Float(string='Free BU', compute='_get_qty_free_bandengan') qty_upcoming = fields.Float(string='Qty Upcoming', compute='_get_qty_upcoming') sla_version = fields.Integer(string="SLA Version", default=0) is_edited = fields.Boolean(string='Is Edited') @@ -377,24 +386,26 @@ class ProductProduct(models.Model): @api.constrains('name','default_code') def _check_duplicate_product(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), - '|', - ('name', 'in', [template.name for template in product.product_tmpl_id] or [product.name]), - ('default_code', 'in', [template.default_code for template in product.product_tmpl_id] or [product.default_code])] - - domain.append(('id', '!=', product.id)) - massage="SKU atau Name yang anda pakai sudah digunakan di product lain" - existing_purchase = self.search(domain, limit=1) - if existing_purchase: - raise UserError(massage) - 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 self.env.user.is_purchasing_manager or self.env.user.is_editor_product or self.env.user.id in [1, 25]: + continue + + if product.write_date == product.create_date: + domain = [ + ('default_code', '!=', False), + '|', + ('name', 'in', [template.name for template in product.product_tmpl_id] or [product.name]), + ('default_code', 'in', [template.default_code for template in product.product_tmpl_id] or [product.default_code])] + + domain.append(('id', '!=', product.id)) + massage="SKU atau Name yang anda pakai sudah digunakan di product lain" + existing_purchase = self.search(domain, limit=1) + if existing_purchase: + raise UserError(massage) + 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('Anda tidak berhak merubah data product ini') @api.constrains('name') def _validate_name(self): @@ -439,6 +450,11 @@ class ProductProduct(models.Model): for product in self: qty_available = product.qty_incoming_bandengan + product.qty_onhand_bandengan - product.qty_outgoing_bandengan product.qty_available_bandengan = qty_available + + def _get_qty_free_bandengan(self): + for product in self: + qty_free = product.qty_onhand_bandengan - product.qty_outgoing_bandengan + product.qty_free_bandengan = qty_free # def write(self, vals): # if 'solr_flag' not in vals: |
