summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/product_template.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
-rwxr-xr-xindoteknik_custom/models/product_template.py94
1 files changed, 79 insertions, 15 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 2ca4925b..25473ab8 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -374,6 +374,9 @@ class ProductProduct(models.Model):
is_edited = fields.Boolean(string='Is Edited')
qty_sold = fields.Float(string='Sold Quantity', compute='_get_qty_sold')
short_spesification = fields.Char(string='Short Spesification')
+ max_qty_reorder = fields.Float(string='Max Qty Reorder', compute='_get_max_qty_reordering_rule')
+ qty_rpo = fields.Float(string='Qty RPO', compute='_get_qty_rpo')
+ plafon_qty = fields.Float(string='Max Plafon', compute='_get_plafon_qty_product')
def _get_clean_website_description(self):
for rec in self:
@@ -389,23 +392,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([
@@ -464,6 +490,16 @@ class ProductProduct(models.Model):
qty = sum(qty_incoming.mapped('product_uom_qty'))
product.qty_incoming_bandengan = qty
+ def _get_qty_incoming_bandengan_with_exclude(self):
+ for product in self:
+ qty_incoming = self.env['stock.move'].search([
+ ('product_id', '=', product.id),
+ ('location_dest_id', 'in', [57, 83]),
+ ('state', 'not in', ['done', 'cancel'])
+ ])
+ qty = sum(qty_incoming.mapped('product_uom_qty'))
+ product.qty_incoming_bandengan = qty
+
def _get_qty_outgoing_bandengan(self):
for product in self:
qty_incoming = self.env['stock.move'].search([
@@ -487,13 +523,41 @@ class ProductProduct(models.Model):
def _get_qty_available_bandengan(self):
for product in self:
qty_available = product.qty_incoming_bandengan + product.qty_onhand_bandengan - product.qty_outgoing_bandengan
- product.qty_available_bandengan = qty_available
+ product.qty_available_bandengan = qty_available or 0
def _get_qty_free_bandengan(self):
for product in self:
qty_free = product.qty_onhand_bandengan - product.qty_outgoing_bandengan
product.qty_free_bandengan = qty_free
-
+
+ def _get_max_qty_reordering_rule(self):
+ for product in self:
+ reordering = self.env['stock.warehouse.orderpoint'].search([
+ ('product_id', '=', product.id)
+ ], limit=1)
+ if not reordering:
+ product.max_qty_reorder = 0
+ else:
+ product.max_qty_reorder = reordering.product_max_qty
+
+ def _get_qty_rpo(self):
+ for product in self:
+ rpo = self.env['v.requisition.match.po'].search([
+ ('product_id', '=', product.id)
+ ], limit=1)
+ if not rpo:
+ product.qty_rpo = 0
+ else:
+ product.qty_rpo = rpo.qty_rpo
+
+ def _get_plafon_qty_product(self):
+ for product in self:
+ qty_available = product.qty_available_bandengan
+ max_qty = product.max_qty_reorder
+ qty_rpo = product.qty_rpo
+ product.plafon_qty = max_qty - qty_available + qty_rpo
+
+
# def write(self, vals):
# if 'solr_flag' not in vals:
# for variant in self: