summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-08-31 11:57:26 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-08-31 11:57:26 +0700
commita0d1350c1eb7b93007ff7e11cf846263d558fc87 (patch)
tree0f3a1d987ef6192281263cdabf42a5db824fc752
parentb7dba2d8eed3c2af22dca53a916f12e9b842c2aa (diff)
parent76e97903641e6dc35f4158f2a08cfa70bed50afe (diff)
Merge branch 'validate-product' into production
# Conflicts: # indoteknik_custom/models/product_template.py
-rwxr-xr-xindoteknik_custom/models/product_template.py84
-rwxr-xr-xindoteknik_custom/models/purchase_pricelist.py23
-rwxr-xr-xindoteknik_custom/views/purchase_pricelist.xml2
3 files changed, 108 insertions, 1 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 019d229c..707a8381 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -51,7 +51,50 @@ class ProductTemplate(models.Model):
is_new_product = fields.Boolean(string='Produk Baru',
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_edit = fields.Boolean(string="Update Counter", default=True)
+ # def write(self, vals):
+ # if not self.env.user.is_purchasing_manager:
+ # for product in self:
+
+ # domain = [
+ # ('id', '=', product.id),
+ # ('create_date', '<=', product.write_date),
+ # ('name', '=', product.name),
+ # ('default_code', '=', product.default_code)
+ # ]
+
+ # existing_purchase = self.search(domain, limit=1)
+ # if existing_purchase:
+ # raise UserError("Hanya Pak Tyas yang bisa mengedit product")
+ # return super(ProductTemplate, self).write(vals)
+
+ @api.constrains('name','default_code',)
+ def _check_duplicate_product(self):
+ if not self.env.user.is_purchasing_manager:
+ for product in self:
+ if product.write_date == product.create_date:
+ domain = [
+ ('default_code', '!=', False),
+ '|',
+ ('name', '=', product.name),
+ ('default_code', '=', product.default_code)]
+
+ domain.append(('id', '!=', product.id))
+ massage="SKU atau Name yang anda pakai sudah digunakan di product lain"
+ existing_purchase = self.search(domain, limit=1)
+ if existing_purchase:
+ raise UserError(massage)
+ else:
+ domain = [
+ ('id', '=', product.id)
+ ]
+ massage="Hanya Pak Tyas Yang Dapat Merubah Data Product"
+ existing_purchase = self.search(domain, limit=1)
+ if existing_purchase:
+ raise UserError(massage)
+
+
@api.constrains('name')
def _validate_name(self):
pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/%-]+$'
@@ -289,6 +332,47 @@ class ProductProduct(models.Model):
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')
sla_version = fields.Integer(string="SLA Version", default=0)
+ is_edit = fields.Boolean(string="Update Counter", default=True)
+
+ # def write(self, vals):
+ # if not self.env.user.is_purchasing_manager:
+ # for product in self:
+ # domain = [
+ # ('id', '=', product.id),
+ # ('create_date', '<=', product.write_date),
+ # ('name', '=', product.name),
+ # ('default_code', '=', product.default_code)
+ # ]
+
+ # existing_purchase = self.search(domain, limit=1)
+ # if existing_purchase:
+ # raise UserError("Hanya Pak Tyas yang bisa mengedit product")
+ # return super(ProductProduct, self).write(vals)
+
+ @api.constrains('name','default_code',)
+ def _check_duplicate_product(self):
+ if not self.env.user.is_purchasing_manager:
+ for product in self:
+ if product.write_date == product.create_date:
+ domain = [
+ ('default_code', '!=', False),
+ '|',
+ ('name', '=', product.name),
+ ('default_code', '=', product.default_code)]
+
+ domain.append(('id', '!=', product.id))
+ massage="SKU atau Name yang anda pakai sudah digunakan di product lain"
+ existing_purchase = self.search(domain, limit=1)
+ if existing_purchase:
+ raise UserError(massage)
+ else:
+ domain = [
+ ('id', '=', product.id)
+ ]
+ massage="Hanya Pak Tyas Yang Dapat Merubah Data Product"
+ existing_purchase = self.search(domain, limit=1)
+ if existing_purchase:
+ raise UserError(massage)
@api.constrains('name')
def _validate_name(self):
diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py
index 419ca8e0..5d077e04 100755
--- a/indoteknik_custom/models/purchase_pricelist.py
+++ b/indoteknik_custom/models/purchase_pricelist.py
@@ -27,3 +27,26 @@ class PurchasePricelist(models.Model):
self.system_last_update = current_time
else:
self.human_last_update = current_time
+
+ @api.constrains('vendor_id', 'product_id','human_last_update','write_date')
+ def _check_duplicate_purchase_pricelist(self):
+ for price in self:
+ if price.write_date == price.create_date:
+ domain = [
+ ('product_id', '=', price.product_id.id),
+ ('vendor_id', '=', price.vendor_id.id)
+ ]
+
+ domain.append(('id', '!=', price.id))
+ massage="Product dan vendor yang anda gunakan sudah ada di purchase pricelist"
+ existing_purchase = self.search(domain, limit=1)
+ if existing_purchase:
+ raise UserError(massage)
+ else:
+ domain = [
+ ('id', '=', price.id)
+ ]
+ massage="Tidak Dapat Merubah Product"
+ existing_purchase = self.search(domain, limit=1)
+ if existing_purchase:
+ raise UserError(massage) \ No newline at end of file
diff --git a/indoteknik_custom/views/purchase_pricelist.xml b/indoteknik_custom/views/purchase_pricelist.xml
index f9fd52ba..5c63676d 100755
--- a/indoteknik_custom/views/purchase_pricelist.xml
+++ b/indoteknik_custom/views/purchase_pricelist.xml
@@ -19,7 +19,7 @@
<field name="name">purchase.pricelist.form</field>
<field name="model">purchase.pricelist</field>
<field name="arch" type="xml">
- <form>
+ <form edit="0">
<sheet>
<group>
<group>