summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-08-28 15:04:51 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-08-28 15:04:51 +0700
commit61c89397e839f546c796a596a1fbbc840aa85311 (patch)
treedd55b5844277f7a7c6e4ba60cf13f684d77959fb
parent203feb6018c55c108c31f4c0e03d38a8f39af52e (diff)
Validate Data Product & Purchase Pricelist
-rwxr-xr-xindoteknik_custom/models/product_template.py119
-rwxr-xr-xindoteknik_custom/models/purchase_pricelist.py23
-rwxr-xr-xindoteknik_custom/views/purchase_pricelist.xml2
3 files changed, 142 insertions, 2 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 52f72729..3352c6b0 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -51,7 +51,67 @@ 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',
+ 'sequence',
+ 'responsible_id',
+ 'list_price',
+ 'standard_price',
+ 'qty_available',
+ 'virtual_available',
+ 'uom_id',
+ 'activity_exception_decoration',
+ 'web_tax_id',
+ 'categ_id',
+ 'taxes_id',
+ 'barcode',
+ 'x_manufacture',
+ 'x_model_product',
+ 'x_studio_field_tGhJR',
+ 'attribute_line_ids',)
+ 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/%]+$'
@@ -59,7 +119,7 @@ class ProductTemplate(models.Model):
pattern_suggest = r'[a-zA-Z0-9\[\]\(\)\.\s/%]+'
suggest = ''.join(re.findall(pattern_suggest, self.name))
raise UserError(f'Nama hanya bisa menggunakan angka, huruf kecil, huruf besar, titik, kurung lengkung, kurung siku, garis miring. Contoh: {suggest}')
-
+
# def write(self, vals):
# if 'solr_flag' not in vals and self.solr_flag == 1:
# vals['solr_flag'] = 2
@@ -287,6 +347,63 @@ 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',
+ 'product_template_attribute_value_ids',
+ 'lst_price',
+ 'standard_price',
+ 'qty_available',
+ 'outgoing_qty',
+ 'incoming_qty',
+ 'virtual_available',
+ 'web_tax_id',
+ 'categ_id',
+ 'taxes_id',
+ 'barcode',
+ 'x_manufacture',
+ 'x_model_product',
+ 'x_studio_field_tGhJR',
+ )
+ 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>