From 4f5594be8d73f88fbb42671525d0d2c6ed977abe Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 21 May 2024 16:00:12 +0700 Subject: create function to update internal reference variants --- indoteknik_custom/models/product_template.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 8494e18a..97ad07a7 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -350,6 +350,18 @@ class ProductProduct(models.Model): is_edited = fields.Boolean(string='Is Edited') qty_sold = fields.Float(string='Sold Quantity', compute='_get_qty_sold') + def update_internal_reference_variants(self, limit=100): + variants = self.env['product.product'].search([ + ('default_code', '=', False), + ('type', '=', 'product'), + ('active', '=', True) + ], limit=limit, order='write_date desc') + for variant in variants: + if not variant.default_code: + variant.default_code = 'ITV.'+str(variant.id) + + _logger.info('Updated variant %s' % variant.name) + def _get_po_suggest(self, qty_purchase): if self.qty_available_bandengan < qty_purchase: return 'harus beli' -- cgit v1.2.3