summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/product_template.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-11-11 14:11:42 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-11-11 14:11:42 +0700
commitfd6b9b5395b04135d9f0afdc0859fb4f07d280b4 (patch)
treebe6e7a4f201b949a3b06e0c020c668ba2b0730fa /indoteknik_custom/models/product_template.py
parentf787f06a341f1775151d98be4490fe6126c511cd (diff)
parent9a0fd25e54491bd14a5b29b62b31a440dfa1bebc (diff)
Merge branch 'production' into feature/max_plafon_order_qty
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
-rwxr-xr-xindoteknik_custom/models/product_template.py49
1 files changed, 36 insertions, 13 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index d3343e75..3bb06eaf 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -391,23 +391,46 @@ class ProductProduct(models.Model):
@api.constrains('active')
def archive_product(self):
for product in self:
+ if self.env.context.get('skip_unpublished_constraint'):
+ continue # Mencegah looping saat dipanggil dari metode lain
+
product_template = product.product_tmpl_id
variants = product_template.product_variant_ids
- if product_template.active and product.active:
- if not product.active and len(variants) == 1:
- product_template.with_context(skip_active_constraint=True).active = False
- product_template.unpublished = True
- elif not product.active and len(variants) > 1:
+ if len(variants) == 1:
+ # Jika hanya ada satu varian, atur status `unpublished` berdasarkan `active`
+ product_template.with_context(skip_unpublished_constraint=True).unpublished = not product.active
+ product.with_context(skip_unpublished_constraint=True).unpublished = not product.active
+ else:
+ if product.active:
+ product.with_context(skip_unpublished_constraint=True).unpublished = False
+ product_template.with_context(skip_unpublished_constraint=True).unpublished = any(variant.active for variant in variants)
+ else:
+ product.with_context(skip_unpublished_constraint=True).unpublished = True
all_inactive = all(not variant.active for variant in variants)
- if all_inactive:
- product_template.with_context(skip_active_constraint=True).active = False
- product_template.unpublished = True
- else:
- continue
- if any(variant.active for variant in variants):
- product_template.unpublished = False
- variants.unpublished = False
+ product_template.with_context(skip_unpublished_constraint=True).unpublished = all_inactive
+
+ @api.constrains('unpublished')
+ def archive_product_unpublished(self):
+ for product in self:
+ if self.env.context.get('skip_active_constraint'):
+ continue # Mencegah looping saat dipanggil dari metode lain
+
+ product_template = product.product_tmpl_id
+ variants = product_template.product_variant_ids
+
+ if len(variants) == 1:
+ # Jika hanya ada satu varian, atur status `unpublished` pada template, tetapi biarkan `active` tetap True
+ product_template.with_context(skip_active_constraint=True).unpublished = product.unpublished
+ else:
+ if not product.unpublished:
+ # Jika `unpublished` adalah False, pastikan `active` tetap True
+ product.with_context(skip_active_constraint=True).active = True
+ product_template.with_context(skip_active_constraint=True).active = any(not variant.unpublished for variant in variants)
+ else:
+ # Jika `unpublished` adalah True, atur template hanya jika semua varian di-unpublished
+ all_unpublished = all(variant.unpublished for variant in variants)
+ product_template.with_context(skip_active_constraint=True).active = not all_unpublished
def update_internal_reference_variants(self, limit=100):
variants = self.env['product.product'].search([