diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-16 15:24:28 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-16 15:24:28 +0700 |
| commit | 6d9ac5debfc7f8809e627900555301aac6ab6083 (patch) | |
| tree | 702654e125c3fa4ce72ac0e60677a04dff75ba57 | |
| parent | f3e37cbd999409929703ebddef5b487a7daf4940 (diff) | |
Add qty sold field and solr data
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 15 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_product.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_template.py | 3 |
3 files changed, 17 insertions, 2 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index b1930ada..da1a111f 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -52,7 +52,11 @@ 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') + + 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 = [] @@ -331,6 +335,15 @@ class ProductProduct(models.Model): qty_incoming_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_incoming_bandengan') 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_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 = [] diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 31a0026d..720be7fa 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -64,6 +64,7 @@ class ProductProduct(models.Model): 'attributes': [x.name for x in variant.product_template_attribute_value_ids], 'has_product_info_b': True, 'publish_b': variant.product_tmpl_id.active and variant.product_tmpl_id.type == 'product', + 'qty_sold_f': variant.qty_sold }) self.solr().add(docs=[document], softCommit=True) diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index d7439bcb..cc8d4bf2 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -80,7 +80,8 @@ class ProductTemplate(models.Model): "category_name": category_name, "description_t": template.website_description or '', 'has_product_info_b': True, - 'publish_b': template.active and template.type == 'product' + 'publish_b': template.active and template.type == 'product', + "qty_sold_f": template.qty_sold }) self.solr().add(docs=[document], softCommit=True) |
