diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-10 13:40:58 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-10 13:40:58 +0700 |
| commit | 2aee5a44abbe36961dfe23cc3d656aa48e11e0f9 (patch) | |
| tree | 8ec2b6552aaef4e14539aa52ed796552e24180d6 /indoteknik_custom/models/product_template.py | |
| parent | 6a87e59e7220bdfa78e98b23003ccc4ef41bd0ce (diff) | |
| parent | b4e74170aeaf00937f78e5af9047218ddb17516c (diff) | |
Merge branch 'production' into change/feature/promotion-program
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index defcbdd4..d1de2221 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -52,7 +52,15 @@ 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') - + qty_sold = fields.Float(string='Sold Quantity', compute='_get_qty_sold') + kind_of = fields.Selection([ + ('sp', 'Spare Part'), + ('acc', 'Accessories') + ], string='Kind of', copy=False) + + def _get_qty_sold(self): + for rec in self: + rec.qty_sold = sum(x.qty_sold for x in rec.product_variant_ids) def day_product_to_edit(self): day_products = [] @@ -184,12 +192,7 @@ class ProductTemplate(models.Model): def _compute_web_price(self): for template in self: - products = self.env['product.product'].search([ - ('product_tmpl_id', '=', template.id), - ('active', 'in', [True, False]) - ]) - for variants in products: - template.web_price = variants[0].web_price + template.web_price = template.product_variant_id.web_price def _have_promotion_program(self): for template in self: @@ -308,6 +311,12 @@ class ProductTemplate(models.Model): } self.env['token.storage'].create([values]) return values + + def write(self, vals): + if self.id == 224484: + raise UserError('Tidak dapat mengubah produk sementara') + + return super(ProductTemplate, self).write(vals) class ProductProduct(models.Model): _inherit = "product.product" @@ -329,8 +338,22 @@ class ProductProduct(models.Model): material = fields.Char(string='Material') qty_onhand_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_onhand_bandengan') qty_incoming_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_incoming_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') + qty_sold = fields.Float(string='Sold Quantity', compute='_get_qty_sold') + + def _get_qty_upcoming(self): + for product in self: + product.qty_upcoming = product.incoming_qty + product.qty_available + + def _get_qty_sold(self): + for product in self: + order_line = self.env['sale.order.line'].search([ + ('order_id.state', 'in', ['done', 'sale']), + ('product_id', '=', product.id) + ]) + product.qty_sold = sum(x.product_uom_qty for x in order_line) def day_product_to_edit(self): day_products = [] @@ -401,9 +424,9 @@ class ProductProduct(models.Model): def _compute_web_price(self): for product in self: - pricelist_id = self.env.context.get('pricelist') + pricelist_id = self.env['ir.config_parameter'].sudo().get_param('product.pricelist.default_price_id_v2') - domain = [('pricelist_id', '=', pricelist_id or 1), ('product_id', '=', product.id)] + domain = [('pricelist_id.id', '=', pricelist_id or 17022), ('product_id.id', '=', product.id)] product_pricelist_item = self.env['product.pricelist.item'].search(domain, limit=1) if product_pricelist_item.base_pricelist_id: |
