summaryrefslogtreecommitdiff
path: root/indoteknik_custom
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-01-29 14:26:39 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-01-29 14:26:39 +0700
commit3877bf37dae2db272b869f829ed52ef77689cc5d (patch)
tree46523b9c4306b5457924420f53e832da1c296224 /indoteknik_custom
parent4a35b0d5432ed38395fa8f8cb6ebcfb5e0887f28 (diff)
parentd62a28e8760c86e2c0a6cb7469f626d9447272be (diff)
Merge branch 'production' of https://bitbucket.org/altafixco/indoteknik-addons into production
Diffstat (limited to 'indoteknik_custom')
-rw-r--r--indoteknik_custom/models/account_move.py2
-rw-r--r--indoteknik_custom/models/base_import_import.py27
-rwxr-xr-xindoteknik_custom/models/product_template.py92
-rwxr-xr-xindoteknik_custom/models/purchase_order_line.py32
-rwxr-xr-xindoteknik_custom/models/purchase_pricelist.py4
-rw-r--r--indoteknik_custom/models/stock_picking.py2
6 files changed, 83 insertions, 76 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index 592a3ae7..a9db212f 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -38,7 +38,7 @@ class AccountMove(models.Model):
sale_id = fields.Many2one('sale.order', string='Sale Order')
reklas_id = fields.Many2one('account.move', string='Nomor CAB', domain="[('partner_id', '=', partner_id)]")
new_invoice_day_to_due = fields.Integer(string="New Day Due", compute="_compute_invoice_day_to_due")
- date_efaktur_upload = fields.Datetime(string='eFaktur Upload Date')
+ date_efaktur_upload = fields.Datetime(string='eFaktur Upload Date', tracking=True)
@api.constrains('efaktur_document')
def _constrains_date_efaktur(self):
diff --git a/indoteknik_custom/models/base_import_import.py b/indoteknik_custom/models/base_import_import.py
index 9cffa6e6..bc3b0e37 100644
--- a/indoteknik_custom/models/base_import_import.py
+++ b/indoteknik_custom/models/base_import_import.py
@@ -1,6 +1,8 @@
+from datetime import datetime
+
from odoo import models
from odoo.exceptions import UserError
-from datetime import datetime
+
class Import(models.TransientModel):
_inherit = 'base_import.import'
@@ -8,8 +10,8 @@ class Import(models.TransientModel):
def _get_config_enable_import(self):
return self.env['ir.config_parameter'].sudo().get_param('base_import.import.enable_import', '')
- def _get_config_restrict_model(self):
- return self.env['ir.config_parameter'].sudo().get_param('base_import.import.restrict_model', '')
+ def _get_config_allowed_model(self):
+ return self.env['ir.config_parameter'].sudo().get_param('base_import.import.allowed_model', '')
def _check_time_range(self, config_string):
current_time = datetime.now().time()
@@ -27,19 +29,20 @@ class Import(models.TransientModel):
def _check_enable_import(self):
enable_import = self._get_config_enable_import()
- restrict_model = self._get_config_restrict_model()
-
- if self.res_model not in restrict_model:
- return True
+ allowed_model = self._get_config_allowed_model()
- if enable_import.lower() == 'true':
- return True
- elif enable_import.lower() == 'false':
+ is_allowed = False
+ if (allowed_model != '-' and self.res_model in allowed_model) or allowed_model == 'ALL':
+ is_allowed = True
+
+ if enable_import.lower() == 'false':
return False
- elif '-' in enable_import:
+ elif enable_import.lower() == 'true' and is_allowed:
+ return True
+ elif '-' in enable_import and is_allowed:
return self._check_time_range(enable_import)
- return True
+ return False
def _unable_import_notif(self):
enable_import_config = self._get_config_enable_import()
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index bdbc391d..30d89356 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -74,32 +74,34 @@ class ProductTemplate(models.Model):
@api.constrains('name', 'default_code')
def _check_duplicate_product(self):
for product in self:
- if not self.env.user.is_purchasing_manager and not self.env.user.is_editor_product and self.env.user.id not in [1, 25]:
- domain = [('default_code', '!=', False)]
-
- if product.product_variant_ids:
- domain.extend([
- '|',
- ('name', 'in', [variants.name for variants in product.product_variant_ids]),
- ('default_code', 'in', [variants.default_code for variants in product.product_variant_ids])
- ])
- else:
- domain.extend([
- '|',
- ('name', 'in', [product.name]),
- ('default_code', 'in', [product.default_code])
- ])
-
- domain.append(('id', '!=', product.id))
-
- if product.write_date == product.create_date:
- message = "SKU atau Name yang Anda gunakan sudah digunakan di produk lain"
- 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)
+ if self.env.user.is_purchasing_manager or self.env.user.is_editor_product or self.env.user.id in [1, 25]:
+ continue
+
+ domain = [('default_code', '!=', False)]
+
+ if product.product_variant_ids:
+ domain.extend([
+ '|',
+ ('name', 'in', [variants.name for variants in product.product_variant_ids]),
+ ('default_code', 'in', [variants.default_code for variants in product.product_variant_ids])
+ ])
+ else:
+ domain.extend([
+ '|',
+ ('name', 'in', [product.name]),
+ ('default_code', 'in', [product.default_code])
+ ])
+
+ domain.append(('id', '!=', product.id))
+
+ if product.write_date == product.create_date:
+ message = "SKU atau Name yang Anda gunakan sudah digunakan di produk lain"
+ elif all(day_product > 0 for day_product in product.day_product_to_edit()):
+ domain = [('id', '=', product.id)]
+ message = "Anda tidak berhak merubah data produk ini"
+ existing_purchase = self.search(domain, limit=1)
+ if existing_purchase:
+ raise UserError(message)
@api.constrains('name')
def _validate_name(self):
@@ -379,24 +381,26 @@ class ProductProduct(models.Model):
@api.constrains('name','default_code')
def _check_duplicate_product(self):
for product in self:
- if not self.env.user.is_purchasing_manager and not self.env.user.is_editor_product and self.env.user.id not in [1, 25]:
- if product.write_date == product.create_date:
- domain = [
- ('default_code', '!=', False),
- '|',
- ('name', 'in', [template.name for template in product.product_tmpl_id] or [product.name]),
- ('default_code', 'in', [template.default_code for template in product.product_tmpl_id] or [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)
- 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 self.env.user.is_purchasing_manager or self.env.user.is_editor_product or self.env.user.id in [1, 25]:
+ continue
+
+ if product.write_date == product.create_date:
+ domain = [
+ ('default_code', '!=', False),
+ '|',
+ ('name', 'in', [template.name for template in product.product_tmpl_id] or [product.name]),
+ ('default_code', 'in', [template.default_code for template in product.product_tmpl_id] or [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)
+ 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('Anda tidak berhak merubah data product ini')
@api.constrains('name')
def _validate_name(self):
diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py
index c7da0e24..465944d5 100755
--- a/indoteknik_custom/models/purchase_order_line.py
+++ b/indoteknik_custom/models/purchase_order_line.py
@@ -2,6 +2,7 @@ from odoo import fields, models, api, _
from odoo.exceptions import AccessError, UserError, ValidationError
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
import logging
+from datetime import datetime
_logger = logging.getLogger(__name__)
@@ -103,24 +104,19 @@ class PurchaseOrderLine(models.Model):
return res
def _get_valid_purchase_price(self, purchase_price):
- p_price = 0
- taxes = False
-
- if purchase_price.system_price > 0 and purchase_price.product_price > 0:
- if purchase_price.human_last_update > purchase_price.system_last_update:
- p_price = purchase_price.product_price
- taxes = purchase_price.taxes_product_id
- else:
- p_price = purchase_price.system_price
- taxes = purchase_price.taxes_system_id
- elif purchase_price.system_price > 0 and purchase_price.product_price == 0:
- p_price = purchase_price.system_price
- taxes = purchase_price.taxes_system_id
- elif purchase_price.system_price == 0 and purchase_price.product_price > 0:
- p_price = purchase_price.product_price
- taxes = purchase_price.taxes_product_id
-
- return p_price, taxes
+ price = 0
+ taxes = None
+ human_last_update = purchase_price.human_last_update or datetime.min
+ system_last_update = purchase_price.system_last_update or datetime.min
+
+ if system_last_update > human_last_update:
+ price = purchase_price.system_price
+ taxes = [purchase.taxes_system_id.id for purchase in purchase_price ]
+ else:
+ price = purchase_price.product_price
+ taxes = [purchase.taxes_product_id.id for purchase in purchase_price ]
+
+ return price, taxes
def compute_item_margin(self):
sum_so_margin = sum_sales_price = sum_margin = 0
diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py
index c756c301..805ebc89 100755
--- a/indoteknik_custom/models/purchase_pricelist.py
+++ b/indoteknik_custom/models/purchase_pricelist.py
@@ -34,7 +34,11 @@ class PurchasePricelist(models.Model):
@api.constrains('system_last_update','system_price','product_price','human_last_update','taxes_system_id','taxes_product_id')
def _contrains_include_price(self):
+
price_unit, taxes = self._get_valid_price()
+ if price_unit == 0:
+ self.include_price = 0
+ return
# taxes = self.taxes_system_id or self.taxes_product_id
# price_unit = self.system_price or self.product_price
tax_include = taxes.price_include
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 8ff782ba..33946f86 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -81,7 +81,7 @@ class StockPicking(models.Model):
status_printed = fields.Selection([
('not_printed', 'Belum Print'),
('printed', 'Printed')
- ], string='Printed SJ?', copy=False)
+ ], string='Printed?', copy=False)
date_unreserve = fields.Datetime(string="Date Unreserved", copy=False, tracking=True)
date_availability = fields.Datetime(string="Date Availability", copy=False, tracking=True)