summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rwxr-xr-xindoteknik_custom/models/crm_lead.py9
-rw-r--r--indoteknik_custom/models/dunning_run.py76
-rw-r--r--indoteknik_custom/models/ir_attachment.py15
-rwxr-xr-xindoteknik_custom/models/product_template.py51
-rwxr-xr-xindoteknik_custom/models/sale_order.py4
-rw-r--r--indoteknik_custom/models/sales_target.py20
-rwxr-xr-xindoteknik_custom/models/stock_vendor.py36
-rwxr-xr-xindoteknik_custom/models/user_activity_log.py31
-rw-r--r--indoteknik_custom/models/website_ads.py18
10 files changed, 195 insertions, 66 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 8ada3b95..5d5ad0ec 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -44,3 +44,4 @@ from . import x_biaya_kirim
from . import x_manufactures
from . import x_partner_purchase_order
from . import x_product_tags
+from . import website_ads
diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py
index e0a90d9c..3c8b842b 100755
--- a/indoteknik_custom/models/crm_lead.py
+++ b/indoteknik_custom/models/crm_lead.py
@@ -11,6 +11,15 @@ class CrmLead(models.Model):
file_siup = fields.Binary(string="Surat Izin Usaha Perdagangan")
body_html_lead = fields.Text('Body HTML', compute='compute_body_leads')
+ def revert_to_leads(self):
+ opportunities = self.env['crm.lead'].search([
+ ('type', '=', 'opportunity'),
+ ('active', '=', True),
+ ('user_id', '=', False),
+ ])
+ for opportunity in opportunities:
+ opportunity.type = 'lead'
+
@api.onchange('stage_id')
def update_stars(self):
for lead in self:
diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py
index ed9aa7c0..ed5d7bb5 100644
--- a/indoteknik_custom/models/dunning_run.py
+++ b/indoteknik_custom/models/dunning_run.py
@@ -17,8 +17,37 @@ class DunningRun(models.Model):
required=True, change_default=True, index=True, tracking=1)
dunning_line = fields.One2many('dunning.run.line', 'dunning_id', string='Dunning Lines', auto_join=True)
# dunning_level = fields.Integer(string='Dunning Level', default=30, help='30 hari sebelum jatuh tempo invoice')
+ date_kirim_tukar_faktur = fields.Date(string='Kirim Faktur')
+ resi_tukar_faktur = fields.Char(string='Resi Faktur')
+ date_terima_tukar_faktur = fields.Date(string='Terima Faktur')
+ shipper_faktur_id = fields.Many2one('delivery.carrier', string='Shipper Faktur')
+ is_validated = fields.Boolean(string='Validated')
+
+ def copy_date_faktur(self):
+ if not self.is_validated:
+ raise UserError('Harus di validate dulu')
+ for line in self.dunning_line:
+ invoice = line.invoice_id
+ if not invoice.date_kirim_tukar_faktur:
+ invoice.date_kirim_tukar_faktur = self.date_kirim_tukar_faktur
+ if not invoice.resi_tukar_faktur:
+ invoice.resi_tukar_faktur = self.resi_tukar_faktur
+ if not invoice.date_terima_tukar_faktur:
+ invoice.date_terima_tukar_faktur = self.date_terima_tukar_faktur
+ if not invoice.shipper_faktur_id:
+ invoice.shipper_faktur_id = self.shipper_faktur_id
+
+ def validate_dunning(self):
+ if not self.dunning_line:
+ raise UserError('Dunning Line masih kosong, generate dulu')
+ else:
+ self.is_validated = True
def generate_dunning_line(self):
+ if self.is_validated:
+ raise UserError('Sudah di validate, tidak bisa digenerate ulang')
+ if self.dunning_line:
+ raise UserError('Harus hapus semua line jika ingin generate ulang')
if self.partner_id.parent_id:
raise UserError('Harus pilih parent company')
@@ -29,21 +58,27 @@ class DunningRun(models.Model):
for partner in partners:
query = [
('move_type', '=', 'out_invoice'),
+ ('state', '=', 'posted'),
('partner_id', '=', partner.id),
- ('outstanding_amount', '>', 0),
+ # ('amount_residual_signed', '>', 0),
+ ('date_kirim_tukar_faktur', '=', False),
]
invoices = self.env['account.move'].search(query, order='invoice_date')
+ count = 0
for invoice in invoices:
- parameter_line = {
+ self.env['dunning.run.line'].create([{
'dunning_id': self.id,
- 'partner_id': invoice.partner_id,
+ 'partner_id': invoice.partner_id.id,
'invoice_id': invoice.id,
'date_invoice': invoice.invoice_date,
- 'efaktur_id': invoice.efaktur_id,
+ 'efaktur_id': invoice.efaktur_id.id,
'reference': invoice.ref,
- 'open_amt': invoice.outstanding_amount
- }
- self.env['dunning.run.line'].create([parameter_line])
+ 'total_amt': invoice.amount_total,
+ 'open_amt': invoice.amount_residual_signed,
+ 'due_date': invoice.invoice_date_due
+ }])
+ count += 1
+ _logger.info("Dunning Line generated %s" % count)
@api.model
def create(self, vals):
@@ -51,33 +86,6 @@ class DunningRun(models.Model):
result = super(DunningRun, self).create(vals)
return result
- def generate_dunning_line(self):
- # validation
- if not self.partner_id:
- raise UserError('Customer harus diisi')
-
- invoices = self.env['account.move'].search([
- ('amount_residual_signed', '>', 0),
- ('partner_id', '=', self.partner_id.id),
- ('move_type', '=', 'out_invoice'),
- ('state', '=', 'posted'),
- ])
- count = 0
- for invoice in invoices:
- self.env['dunning.run.line'].create([{
- 'dunning_id': self.id,
- 'partner_id': invoice.partner_id.id,
- 'invoice_id': invoice.id,
- 'date_invoice': invoice.invoice_date,
- 'efaktur_id': invoice.efaktur_id.id,
- 'reference': invoice.ref,
- 'total_amt': invoice.amount_total,
- 'open_amt': invoice.amount_residual_signed,
- 'due_date': invoice.invoice_date_due
- }])
- count += 1
- _logger.info("Dunning Line generated %s" % count)
-
class DunningRunLine(models.Model):
_name = 'dunning.run.line'
diff --git a/indoteknik_custom/models/ir_attachment.py b/indoteknik_custom/models/ir_attachment.py
index 278eb938..fd86ab1b 100644
--- a/indoteknik_custom/models/ir_attachment.py
+++ b/indoteknik_custom/models/ir_attachment.py
@@ -9,4 +9,17 @@ class Attachment(models.Model):
@api.autovacuum
def _gc_file_store(self):
- _logger.info("filestore gc checked, removed - override") \ No newline at end of file
+ _logger.info("filestore gc checked, removed - override")
+
+ def is_found(self, model, field, id):
+ attachment = self.search([
+ ('res_model', '=', model),
+ ('res_field', '=', field),
+ ('res_id', '=', int(id))
+ ])
+ return True if attachment else False
+
+ def api_image(self, model, field, id):
+ base_url = self.env['ir.config_parameter'].get_param('web.base.url')
+ is_found = self.is_found(model, field, id)
+ return base_url + 'api/image/' + model + '/' + field + '/' + str(id) if is_found else '' \ No newline at end of file
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 9f0410f4..74b4edb1 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -46,12 +46,33 @@ class ProductTemplate(models.Model):
material = fields.Char(string='Material')
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')
# def write(self, vals):
# if 'solr_flag' not in vals and self.solr_flag == 1:
# vals['solr_flag'] = 2
# return super().write(vals)
+ def update_new_product(self):
+ current_time = datetime.now()
+ delta_time = current_time - timedelta(days=30)
+
+ delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+
+ products = self.env['product.template'].search([
+ ('type', '=', 'product'),
+ ('active', '=', True),
+ ('product_rating', '>', 3),
+ ('create_date', '>=', delta_time),
+ ], limit=100)
+
+ seq = 0
+ for product in products:
+ seq += 1
+ product.is_new_product = True
+ product.seq_new_product = seq
+ _logger.info('Updated New Product %s' % product.name)
+
def update_internal_reference(self):
templates_without_variant = self.env['product.template'].search([
('default_code', '=', False),
@@ -92,33 +113,21 @@ class ProductTemplate(models.Model):
for template in self:
product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1)
- # product_pricelist_default = self.env['ir.config_parameter'].sudo().get_param('product.pricelist.default')
- # product_pricelist_disc = self.env['product.pricelist.item'].search([
- # ('pricelist_id', '=', product_pricelist_default.int()),
- # ('product_id', '=', product.id)], limit=1)
- # disc = product_pricelist_disc.price_discount
-
product_pricelist_item = self.env['product.pricelist.item'].search([
('pricelist_id', '=', 1),
('product_id', '=', product.id)], limit=1)
price = product_pricelist_item.fixed_price
- #
- # if not disc and not price:
- # template.web_price = 0
- # elif not disc:
template.web_price = price
- # else:
- # price_disc = price - (price * disc / 100)
- # template.web_price = price_disc
def _have_promotion_program(self):
for template in self:
- domain = [
- ('rule_products_domain', 'ilike', template.x_manufacture.x_name),
- ('active', '=', True)
- ]
- coupon_program = self.env['coupon.program'].search(domain, limit=1)
- if coupon_program:
+ product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1)
+
+ product_pricelist_item = self.env['product.pricelist.item'].search([
+ ('pricelist_id', '=', 4),
+ ('product_id', '=', product.id)], limit=1)
+ discount = product_pricelist_item.price_discount
+ if discount:
template.have_promotion_program = True
else:
template.have_promotion_program = False
@@ -136,7 +145,7 @@ class ProductTemplate(models.Model):
('active', '=', True),
('last_calculate_rating', '=', False),
# ('id', '=', 22798),
- ], limit=10000)
+ ], limit=100)
for product in products:
# print("Calculate Rating Product ", product)
@@ -161,7 +170,7 @@ class ProductTemplate(models.Model):
('type', '=', 'product'),
('active', '=', True),
('last_calculate_rating', '<', delta_time),
- ], limit=10000)
+ ], limit=100)
for product in products:
print("Calculate Rating Product OutOfDate", product)
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index c8937ca4..5a4a653b 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -197,11 +197,15 @@ class SaleOrder(models.Model):
raise UserError("Payment Term pada Master Data Customer harus diisi")
if not order.partner_id.parent_id.active_limit:
raise UserError("Credit Limit pada Master Data Customer harus diisi")
+ if order.payment_term_id != order.partner_id.parent_id.property_payment_term_id:
+ raise UserError("Payment Term berbeda pada Master Data Customer")
else:
if not order.partner_id.property_payment_term_id:
raise UserError("Payment Term pada Master Data Customer harus diisi")
if not order.partner_id.active_limit:
raise UserError("Credit Limit pada Master Data Customer harus diisi")
+ if order.payment_term_id != order.partner_id.property_payment_term_id:
+ raise UserError("Payment Term berbeda pada Master Data Customer")
if not order.sales_tax_id:
raise UserError("Tax di Header harus diisi")
if not order.carrier_id:
diff --git a/indoteknik_custom/models/sales_target.py b/indoteknik_custom/models/sales_target.py
index ac6405e5..c31a4470 100644
--- a/indoteknik_custom/models/sales_target.py
+++ b/indoteknik_custom/models/sales_target.py
@@ -16,6 +16,26 @@ class SalesTarget(models.Model):
ongoing_omset_adempiere = fields.Float(string='Omset Berjalan ADempiere')
ongoing_omset_total = fields.Float(string='Total Omset', compute='_compute_total_omset')
target = fields.Float(string='Target')
+ ach_per_year = fields.Float(string='Ach/Year%', compute='_compute_achievement')
+ ach_per_month = fields.Float(string='Ach/Month%', compute='_compute_achievement')
+ sales_id = fields.Many2one('res.users', string='Salesperson', compute='_compute_partner')
+ reference = fields.Char(string='Reference', compute='_compute_partner')
+
+ def _compute_partner(self):
+ for sales_target in self:
+ sales_target.sales_id = sales_target.partner_id.user_id
+ sales_target.reference = sales_target.partner_id.reference_number
+
+ def _compute_achievement(self):
+ for sales_target in self:
+ if not sales_target.target or sales_target.target <= 0:
+ sales_target.ach_per_year = 0
+ sales_target.ach_per_month = 0
+ return
+ current_time = datetime.now()
+ current_month = current_time.month
+ sales_target.ach_per_year = sales_target.ongoing_omset_total/sales_target.target*100
+ sales_target.ach_per_month = sales_target.ongoing_omset_total/((sales_target.target/12)*current_month)
def _compute_total_omset(self):
for target in self:
diff --git a/indoteknik_custom/models/stock_vendor.py b/indoteknik_custom/models/stock_vendor.py
index 1a6b4a64..1e5bce16 100755
--- a/indoteknik_custom/models/stock_vendor.py
+++ b/indoteknik_custom/models/stock_vendor.py
@@ -11,27 +11,47 @@ class StockVendor(models.Model):
product_variant_id = fields.Many2one("product.product", string="Product Variant")
quantity = fields.Integer(string="Quantity")
+ cache_reset_status = fields.Selection([
+ ('reset', 'Reset'),
+ ('done', 'Done')
+ ], string="Cache Reset")
+
+ def cache_reset(self):
+ stocks = self.env['stock.vendor'].search([
+ ('cache_reset_status', '=', 'reset'),
+ ])
+
+ templates = []
+ for stock in stocks:
+ templates.append(stock.product_variant_id.product_tmpl_id)
+ # stock.cache_reset_status = 'done'
+ templates = list(dict.fromkeys(templates))
+
+ for template in templates:
+ if template.solr_flag == 1:
+ template.solr_flag = 2
+ _logger.info('Update Solr Flag to 2 %s' % template.name)
def update_product_template(self):
updated_virtual_qty_product_template = self.env['ir.config_parameter'].search([('key', '=', 'updated_virtual_qty_product_template')], limit=1)
updated_virtual_qty_product_template_value = int(updated_virtual_qty_product_template.value)
-
+
limit = 10000
query = [('active', '=', True), ('type', '=', 'product')]
templates = self.env['product.template'].search(query, limit=limit, offset=updated_virtual_qty_product_template_value)
template_count = self.env['product.template'].search_count(query)
-
+
if (updated_virtual_qty_product_template_value + limit) > template_count:
updated_virtual_qty_product_template.value = '0'
else:
updated_virtual_qty_product_template.value = str(limit + updated_virtual_qty_product_template_value)
-
+
for template in templates:
template.virtual_qty = template.qty_stock_vendor or 0
_logger.info("Update Stock Product Template %s : %s" % (template.id, template.virtual_qty))
- @api.onchange('quantity')
- def update_solr_flag(self):
- for stock in self:
- if stock.product_variant_id.product_tmpl_id.solr_flag == 1:
- stock.product_variant_id.product_tmpl_id.solr_flag = 2
+ # @api.onchange('quantity')
+ # def update_solr_flag(self):
+ # for stock in self:
+ # if stock.product_variant_id.product_tmpl_id.solr_flag == 1:
+ # stock.product_variant_id.product_tmpl_id.solr_flag = 2
diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py
index bf1414db..32b389a1 100755
--- a/indoteknik_custom/models/user_activity_log.py
+++ b/indoteknik_custom/models/user_activity_log.py
@@ -14,14 +14,40 @@ class UserActivityLog(models.Model):
res_user_id = fields.Many2one("res.users", string="User")
email = fields.Char(string="Email")
update_product = fields.Boolean(string="Update Product")
+ product_id = fields.Many2one('product.template', string='Product')
+
+ def compile_product(self):
+ logs = self.env['user.activity.log'].search([
+ ('email', '!=', False),
+ ('product_id', '=', False),
+ ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'),
+ ('url', 'not ilike', 'shopping')
+ ], limit=1000, order='create_date desc')
+ for log in logs:
+ _logger.info(log.url)
+ strip_index = i = 0
+ for c in log.url:
+ if c == '-':
+ strip_index = i
+ i += 1
+ product_id = log.url[strip_index + 1:len(log.url)]
+ if '#' in product_id:
+ continue
+ if any(ch.isalpha() for ch in product_id):
+ continue
+ product = self.env['product.template'].search([
+ ('id', '=', product_id)
+ ])
+ log.product_id = product
def clean_activity_log(self):
current_time = datetime.now()
- delta_time = current_time - timedelta(days=60)
+ delta_time = current_time - timedelta(days=180)
delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
self.env['user.activity.log'].search([
('create_date', '<', delta_time),
+ ('email', '=', 'False'),
]).unlink()
def reset_rank_search_weekly(self):
@@ -44,7 +70,8 @@ class UserActivityLog(models.Model):
activity_logs = self.env['user.activity.log'].search([
('url', 'ilike', 'https://indoteknik.co%/shop/product/%'),
('create_date', '>', delta_time),
- ], limit=4000)
+ ('url', 'not ilike', 'shopping'),
+ ], limit=1000)
for activity_log in activity_logs:
_logger.info(activity_log.url)
strip_index = i = 0
diff --git a/indoteknik_custom/models/website_ads.py b/indoteknik_custom/models/website_ads.py
new file mode 100644
index 00000000..ec360294
--- /dev/null
+++ b/indoteknik_custom/models/website_ads.py
@@ -0,0 +1,18 @@
+from odoo import fields, models
+
+
+class WebsiteAds(models.Model):
+ _name = 'website.ads'
+
+ sequence = fields.Integer(string='Sequence')
+ name = fields.Char(string='Name')
+ image = fields.Binary(string='Image')
+ url = fields.Char(string='URL')
+ page = fields.Selection([
+ ('product', 'Product'),
+ ('homepage', 'Home Page')
+ ], string='Page')
+ status = fields.Selection([
+ ('tayang', 'Tayang'),
+ ('tidak_tayang', 'Tidak Tayang')
+ ], string='Status')