summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-09-19 15:28:49 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-09-19 15:28:49 +0700
commit5383121fbdc4e2f899e6bbe7e0402402a8f8eaf4 (patch)
treee348268e3e742e940e3a4a5cad04b4585622ef35
parent1809eb87d20669cb1f2245c7e229d771058c1766 (diff)
fix required field email so
-rwxr-xr-xindoteknik_custom/models/product_template.py36
-rwxr-xr-xindoteknik_custom/views/sale_order.xml2
2 files changed, 24 insertions, 14 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index f186c2bf..cf3df153 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -1,5 +1,5 @@
from odoo import fields, models, api
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, date
from odoo.exceptions import UserError
import logging
import requests
@@ -63,6 +63,15 @@ class ProductTemplate(models.Model):
self._create_solr_queue('_sync_product_template_to_solr')
+ def day_product_to_edit(self):
+ day_products = []
+
+ for product in self:
+ day_product = (product.write_date - product.create_date).days
+ day_products.append(day_product)
+
+ return day_products
+
@api.constrains('name', 'default_code')
def _check_duplicate_product(self):
for product in self:
@@ -86,12 +95,10 @@ class ProductTemplate(models.Model):
if product.write_date == product.create_date:
message = "SKU atau Name yang Anda gunakan sudah digunakan di produk lain"
- else:
+ elif all(day_product > 0 for day_product in product.day_product_to_edit()):
domain = [('id', '=', product.id)]
message = "Hanya Pak Tyas yang dapat merubah data produk"
-
existing_purchase = self.search(domain, limit=1)
-
if existing_purchase:
raise UserError(message)
@@ -334,6 +341,15 @@ class ProductProduct(models.Model):
sla_version = fields.Integer(string="SLA Version", default=0)
is_edited = fields.Boolean(string='Is Edited')
+ def day_product_to_edit(self):
+ day_products = []
+
+ for product in self:
+ day_product = (product.write_date - product.create_date).days
+ day_products.append(day_product)
+
+ return day_products
+
@api.constrains('name','default_code')
def _check_duplicate_product(self):
if not self.env.user.is_purchasing_manager:
@@ -350,18 +366,12 @@ class ProductProduct(models.Model):
existing_purchase = self.search(domain, limit=1)
if existing_purchase:
raise UserError(massage)
- else:
- domain = [
- ('id', '=', product.id),
- ('is_edited', '=', True),
- ]
+ elif all(day_product > 0 for day_product in product.day_product_to_edit()):
+ domain = [('id', '=', product.id)]
existing_purchase = self.search(domain)
if existing_purchase:
raise UserError('Hanya Pak Tyas Yang Dapat Merubah Data Product')
- if not existing_purchase:
- true = True
- self.is_edited = true
-
+
@api.constrains('name')
def _validate_name(self):
pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/%-]+$'
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 221e6118..bfdfc743 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -45,7 +45,7 @@
<field name="customer_type" attrs="{'required': ['|', ('create_date', '&gt;', '2023-06-28'), ('create_date', '=', False)]}"/>
<field name="npwp" placeholder='99.999.999.9-999.999' attrs="{'required': ['|', ('create_date', '&gt;', '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="email" attrs="{'required': [('create_date', '&gt;', '2023-09-28')]}"/>
<field name="due_id" readonly="1"/>
<field name="source_id" domain="[('id', 'in', [32, 59, 60, 61])]" attrs="{'required':[('create_date', '&gt;', '2023-09-10')]}"/>
</field>