diff options
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 10 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_product.py | 5 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_template.py | 47 | ||||
| -rwxr-xr-x | indoteknik_custom/views/product_template.xml | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 1 |
6 files changed, 38 insertions, 28 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 4c11dcef..f186c2bf 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -52,6 +52,16 @@ 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') @api.constrains('name', 'default_code') def _check_duplicate_product(self): diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 8317e1fd..2d8d97bd 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -78,6 +78,7 @@ class SaleOrder(models.Model): amount_voucher_disc = fields.Float(string='Voucher Discount') source_id = fields.Many2one('utm.source', 'Source', domain="[('id', 'in', [32, 59, 60, 61])]") estimated_arrival_days = fields.Integer('Estimated Arrival Days', default=0) + email = fields.Char(string='Email') def _compute_purchase_total(self): for order in self: @@ -172,6 +173,7 @@ class SaleOrder(models.Model): self.npwp = parent_id.npwp self.sppkp = parent_id.sppkp self.customer_type = parent_id.customer_type + self.email = parent_id.email @api.onchange('partner_id') def onchange_partner_id(self): diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 93e26793..d6418ede 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -31,8 +31,6 @@ class ProductProduct(models.Model): solr_model = self.env['apache.solr'] for variant in self: - if not variant.product_tmpl_id.active and variant.product_tmpl_id.type != 'product': - continue category_id = 0 category_name = '' @@ -64,7 +62,8 @@ class ProductProduct(models.Model): 'search_rank_i': variant.product_tmpl_id.search_rank, 'search_rank_weekly_i': variant.product_tmpl_id.search_rank_weekly, 'attributes': [x.name for x in variant.product_template_attribute_value_ids], - 'has_product_info_b': True + 'has_product_info_b': True, + 'publish_b': variant.product_tmpl_id.publish, }) 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 ea976359..7d899873 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -23,9 +23,21 @@ class ProductTemplate(models.Model): 'function_name': function_name }) - @api.constrains('active') - def _create_solr_queue_sync_active(self): - self._create_solr_queue('_sync_active_template_solr') + @api.constrains('active', 'type') + def constrains_active(self): + for template in self: + template.publish = template.active and template.type == 'product' + self._create_solr_queue('_sync_product_template_to_solr') + + @api.constrains('publish') + def constrains_publish(self): + for template in self: + if template.active and template.type == 'product': + continue + template.product_variant_ids.publish = template.publish + self._create_solr_queue('_sync_product_template_to_solr') + + constrains_active._priority = 1 @api.constrains('name', 'default_code', 'weight', 'x_manufacture', 'public_categ_ids', 'search_rank', 'search_rank_weekly', 'image_1920') def _create_solr_queue_sync_product_template(self): @@ -42,25 +54,10 @@ class ProductTemplate(models.Model): product._create_solr_queue('_sync_price_to_solr') product.solr_flag = 1 - def _sync_active_template_solr(self): - for template in self: - if not template.active or template.type != 'product': - template._sync_delete_solr() - else: - template._sync_product_template_to_solr() - template._sync_price_to_solr() - - products = self.env['product.product'].search( - [('product_tmpl_id', '=', template.id), ('active', 'in', [True, False])]) - products._sync_variants_to_solr() - def _sync_product_template_to_solr(self): solr_model = self.env['apache.solr'] for template in self: - if not template.active or template.type != 'product': - continue - variant_names = ', '.join([x.display_name or '' for x in template.product_variant_ids]) variant_codes = ', '.join([x.default_code or '' for x in template.product_variant_ids]) @@ -96,10 +93,15 @@ class ProductTemplate(models.Model): "category_name": category_name, "description_t": template.website_description or '', 'has_product_info_b': True, + 'publish_b': template.publish }) self.solr().add(docs=[document], softCommit=True) - template.product_variant_ids._sync_variants_to_solr() + products = self.env['product.product'].search([ + ('product_tmpl_id', '=', template.id), + ('active', 'in', [True, False]) + ]) + products._sync_variants_to_solr() self.change_solr_data('Perubahan pada data product') if not document.get('has_price_info_b'): @@ -158,12 +160,7 @@ class ProductTemplate(models.Model): if not document.get('has_product_info_b'): template._sync_product_template_to_solr() - def _sync_delete_solr(self): - for rec in self: - self.solr().delete(rec.id) - for variant in rec.product_variant_ids: - variant._sync_delete_solr() - + def solr_results(self, detail=False): solr_model = self.env['apache.solr'] pricelist = self.env.user_pricelist diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index a3a23101..e09fee77 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -15,6 +15,7 @@ <field name="uom_po_id" position="after"> <field name="desc_update_solr" readonly="1" /> <field name="last_update_solr" readonly="1" /> + <field name="publish" /> </field> <page name="inventory" position="after"> <page string="Marketplace" name="marketplace"> diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index c505644d..221e6118 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -45,6 +45,7 @@ <field name="customer_type" attrs="{'required': ['|', ('create_date', '>', '2023-06-28'), ('create_date', '=', False)]}"/> <field name="npwp" placeholder='99.999.999.9-999.999' attrs="{'required': ['|', ('create_date', '>', '2023-06-28'), ('create_date', '=', False)]}"/> <field name="sppkp" attrs="{'invisible': [('customer_type','!=','pkp')], 'required': [('customer_type', '=', 'pkp')]}"/> + <field name="email" required="1"/> <field name="due_id" readonly="1"/> <field name="source_id" domain="[('id', 'in', [32, 59, 60, 61])]" attrs="{'required':[('create_date', '>', '2023-09-10')]}"/> </field> |
