diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-05-09 14:47:45 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-05-09 14:47:45 +0700 |
| commit | 2262f57b0b56b7aa1535600de20b1a1dd611a991 (patch) | |
| tree | 0de5a4c64b6877c801de5e95e6caa6f89e806889 /indoteknik_custom/models | |
| parent | c50611bce3b2a57a7436f3f8b921207e36ff7f27 (diff) | |
| parent | d97277a0847bc57c0bc704c5ea62f75fadb461dc (diff) | |
Merge branch 'release' into staging
Diffstat (limited to 'indoteknik_custom/models')
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 3 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 4 | ||||
| -rw-r--r-- | indoteknik_custom/models/apache_solr.py | 35 | ||||
| -rw-r--r-- | indoteknik_custom/models/brand_vendor.py | 13 | ||||
| -rwxr-xr-x | indoteknik_custom/models/crm_lead.py | 39 | ||||
| -rw-r--r-- | indoteknik_custom/models/procurement_monitoring_detail.py | 73 | ||||
| -rw-r--r-- | indoteknik_custom/models/product_pricelist.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 63 | ||||
| -rw-r--r-- | indoteknik_custom/models/raja_ongkir.py | 24 | ||||
| -rw-r--r-- | indoteknik_custom/models/uangmuka_pembelian.py | 12 | ||||
| -rw-r--r-- | indoteknik_custom/models/uangmuka_penjualan.py | 12 | ||||
| -rwxr-xr-x | indoteknik_custom/models/x_banner_banner.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/x_manufactures.py | 9 |
13 files changed, 236 insertions, 53 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 679004d1..5dc9ce9e 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -58,3 +58,6 @@ from . import uangmuka_penjualan from . import uangmuka_pembelian from . import automatic_purchase from . import apache_solr +from . import raja_ongkir +from . import procurement_monitoring_detail +from . import brand_vendor
\ No newline at end of file diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index db4886f4..56f3e82c 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -36,6 +36,10 @@ class AccountMove(models.Model): res = super(AccountMove, self).action_post() # if not self.env.user.is_accounting: # raise UserError('Hanya Accounting yang bisa Posting') + if self._name == 'account.move': + for entry in self: + for line in entry.line_ids: + line.date_maturity = entry.date return res def _compute_invoice_day_to_due(self): diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 3709e88a..b59f95cc 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -1,20 +1,46 @@ from odoo import models, api, fields from odoo.exceptions import UserError -from datetime import datetime +from datetime import datetime, timedelta import logging import pysolr import time _logger = logging.getLogger(__name__) +_solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) class ApacheSolr(models.Model): _name = 'apache.solr' _order = 'id desc' + def _update_rating_product_to_solr(self, limit=1000): + current_time = datetime.now() + delta_time = current_time - timedelta(days=30) + + current_time = current_time.strftime('%Y-%m-%d %H:%M:%S') + delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + templates = self.env['product.template'].search([ + '&','&', + ('type', '=', 'product'), + ('active', '=', True), + '|', + ('last_calculate_rating', '=', False), + ('last_calculate_rating', '<', delta_time), + ], limit=limit) + documents=[] + for template in templates: + rating = {"set":template.virtual_rating} + document = { + "id": template.id, + "product_rating_f": rating + } + documents.append(document) + template.last_calculate_rating = current_time + _logger.info("[SYNC_PRODUCT_RATING_TO_SOLR] Success Set to solr product %s" % template.id) + _solr.add(documents) + def _sync_product_to_solr(self, limit=500): - # _solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) - _solr = pysolr.Solr('http://192.168.23.5:8983/solr/product/', always_commit=True, timeout=30) + # _solr = pysolr.Solr('http://192.168.23.5:8983/solr/product/', always_commit=True, timeout=30) start_time = time.time() _logger.info('run sync to solr...') query = ["&","&",("type","=","product"),("active","=",True),"|",("solr_flag","=",0),("solr_flag","=",2)] @@ -52,6 +78,7 @@ class ApacheSolr(models.Model): variants_name += variant.display_name or ''+', ' variants_code += variant.default_code or ''+', ' else: + variants_name = template.display_name price_excl = template.product_variant_id._get_website_price_exclude_tax() discount = template.product_variant_id._get_website_disc(0) price_excl_after_disc = template.product_variant_id._get_website_price_after_disc_and_tax() @@ -72,7 +99,7 @@ class ApacheSolr(models.Model): 'display_name_s': template.display_name, 'name_s': template.name, 'default_code_s': template.default_code or '', - 'product_rating_f': template.product_rating, + 'product_rating_f': template.virtual_rating, 'product_id_i': template.id, 'image_s': self.env['ir.attachment'].api_image('product.template', 'image_512', template.id), 'price_f': price_excl, diff --git a/indoteknik_custom/models/brand_vendor.py b/indoteknik_custom/models/brand_vendor.py new file mode 100644 index 00000000..0fd122ca --- /dev/null +++ b/indoteknik_custom/models/brand_vendor.py @@ -0,0 +1,13 @@ +from odoo import models, fields +import logging + +_logger = logging.getLogger(__name__) + + +class BrandVendor(models.Model): + _name = 'brand.vendor' + _order = 'id asc' + + x_manufacture_id = fields.Many2one('x_manufactures', string='Manufacture') + partner_id = fields.Many2one('res.partner', string='Vendor') + priority = fields.Integer(string='Priority', default=0) diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index 1f37005d..e7af4b1c 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -1,4 +1,7 @@ from odoo import fields, models, api +import logging + +_logger = logging.getLogger(__name__) class CrmLead(models.Model): @@ -18,6 +21,11 @@ class CrmLead(models.Model): operator_name = fields.Char('Operator Name', help='Operator yang membalas') order_id = fields.Many2one('sale.order', string='Sales Order', help='Link ke sales order id') + @api.onchange('user_id') + def _change_salesperson_so(self): + if self.order_id: + self.order_id.user_id = self.user_id + def revert_to_leads(self): opportunities = self.env['crm.lead'].search([ ('type', '=', 'opportunity'), @@ -49,18 +57,35 @@ class CrmLead(models.Model): # ('id', '=', 12523) ], limit=1000) for lead in leads: - tags = self.env['crm.tag'].search([('id', '>', 0)]) + _logger.info('processing tagged lead %s' % lead.id) input_tags = [] - for tag in tags: - if tag.name.lower() in lead.body_html_lead.lower(): - input_tags.append(tag.id) - lead.tag_ids = input_tags + if lead.order_id: + last_manufacture_id = 0 + for line in lead.order_id.order_line: + tag = self.env['crm.tag'].search([('name', 'ilike', line.product_id.product_tmpl_id.x_manufacture.x_name)], limit=1) + if tag and tag.id != last_manufacture_id: + last_manufacture_id = tag.id + input_tags.append(tag.id) + input_tags.append(1509) #Website hastag + lead.tag_ids = input_tags + else: + tags = self.env['crm.tag'].search([('id', '>', 0)]) + for tag in tags: + if tag.name.lower() in lead.body_html_lead.lower(): + input_tags.append(tag.id) + if input_tags: + lead.tag_ids = input_tags + else: + input_tags.append(1510) #no tag + lead.tag_ids = input_tags if not lead.partner_id: continue if not lead.user_id or lead.user_id.id == 2: - if lead.partner_id.parent_id: + if lead.partner_id.parent_id.user_id: salesperson_id = lead.partner_id.parent_id.user_id.id - else: + elif lead.partner_id.user_id: salesperson_id = lead.partner_id.user_id.id + else: + salesperson_id = 2 lead.user_id = salesperson_id diff --git a/indoteknik_custom/models/procurement_monitoring_detail.py b/indoteknik_custom/models/procurement_monitoring_detail.py new file mode 100644 index 00000000..6031e04a --- /dev/null +++ b/indoteknik_custom/models/procurement_monitoring_detail.py @@ -0,0 +1,73 @@ +from odoo import fields, models, api, tools +import logging + +_logger = logging.getLogger(__name__) + + +class SaleMonitoringDetail(models.Model): + _name = 'procurement.monitoring.detail' + _auto = False + _rec_name = 'sale_order_id' + + id = fields.Integer() + sale_order_id = fields.Many2one("sale.order", string="Sale Order") + partner_id = fields.Many2one("res.partner", string="Customer") + user_id = fields.Many2one("res.users", string="Salesperson") + product_id = fields.Many2one("product.product", string="Product") + qty_so = fields.Integer(string="Qty SO") + qty_reserved = fields.Integer(string="Qty Reserved") + qty_available = fields.Integer(string="Qty Available") + qty_suggest = fields.Integer(string="Qty Suggest") + qty_po = fields.Integer(string='Qty PO') + date_order = fields.Datetime(string="Date Order") + status = fields.Char(string="Status") + po_ids = fields.Many2many('purchase.order', string='PO', compute='_compute_po') + + def _compute_po(self): + for line in self: + query = [ + ('order_id.sale_order_id', '=', line.sale_order_id.id), + ('order_id.approval_status', '=', 'approved'), + ('product_id', '=', line.product_id.id), + ] + pos = self.env['purchase.order.line'].search(query) + po_ids = [] + for po in pos: + po_ids.append(po.order_id.id) + line.po_ids = po_ids + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW %s AS ( + SELECT + *, + a.qty_so-a.qty_reserved as qty_suggest, + case when a.qty_po >= a.qty_so then 'cukup' + when a.qty_so-a.qty_reserved > 0 then 'harus beli' + else 'cukup' end as status + FROM + ( + SELECT + sol.id AS id, + so.id AS sale_order_id, + so.partner_id as partner_id, + so.user_id, + p.id AS product_id, + sol.product_uom_qty AS qty_so, + get_qty_available(sol.product_id) as qty_available, + get_qty_reserved(so.id, sol.product_id) as qty_reserved, + get_qty_po(so.id, sol.product_id) AS qty_po, + so.date_order AS date_order + FROM sale_order so + JOIN sale_order_line sol ON sol.order_id = so.id + JOIN product_product p ON p.id = sol.product_id + JOIN product_template pt ON pt.id = p.product_tmpl_id + WHERE pt.type IN ('consu','product') + AND so.state IN ('sale','done') + AND so.create_date >= '2022-08-10' + and so.so_status not in ('terproses') + ) a + --where a.qty_po < a.qty_so + ) + """ % self._table) diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py index a309945d..2edaeb80 100644 --- a/indoteknik_custom/models/product_pricelist.py +++ b/indoteknik_custom/models/product_pricelist.py @@ -14,6 +14,7 @@ class ProductPricelist(models.Model): ('all', 'For All User'), ('registered_user', 'Only for Registered User') ], string='Flashsale Option') + banner_top = fields.Binary(string='Banner Top') class ProductPricelistItem(models.Model): diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 74b4edb1..49235ec7 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -29,6 +29,7 @@ class ProductTemplate(models.Model): have_promotion_program = fields.Boolean('Have Promotion Program', compute='_have_promotion_program', help="Punya promotion program gak?") product_rating = fields.Float('Product Rating', help="Digunakan untuk sorting product di website", default=0.0) + virtual_rating = fields.Float('Virtual Rating', compute='_compute_virtual_rating', help="Column Virtual untuk product rating, digunakan oleh Solr", default=0.0) last_calculate_rating = fields.Datetime("Last Calculate Rating") web_price_sorting = fields.Float('Web Price Sorting', help='Hanya digunakan untuk sorting di web, harga tidak berlaku', default=0.0) virtual_qty = fields.Float(string='Virtual Qty', default=0) @@ -53,6 +54,21 @@ class ProductTemplate(models.Model): # vals['solr_flag'] = 2 # return super().write(vals) + def _compute_virtual_rating(self): + for product in self: + rate = 0 + if product.web_price: + rate += 4 + if product.have_promotion_program: #have discount from pricelist + rate += 5 + if product.image_128: + rate += 3 + if product.website_description: + rate += 1 + if product.product_variant_id.qty_stock_vendor > 0: + rate += 2 + product.virtual_rating = rate + def update_new_product(self): current_time = datetime.now() delta_time = current_time - timedelta(days=30) @@ -111,21 +127,21 @@ class ProductTemplate(models.Model): def _compute_web_price(self): for template in self: - product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) + # product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) product_pricelist_item = self.env['product.pricelist.item'].search([ ('pricelist_id', '=', 1), - ('product_id', '=', product.id)], limit=1) + ('product_id', '=', template.product_variant_id.id)], limit=1) price = product_pricelist_item.fixed_price template.web_price = price def _have_promotion_program(self): for template in self: - product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) + # 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) + ('product_id', '=', template.product_variant_id.id)], limit=1) discount = product_pricelist_item.price_discount if discount: template.have_promotion_program = True @@ -134,6 +150,7 @@ class ProductTemplate(models.Model): @api.model def _calculate_rating_product(self): + #["&","&",["type","=","product"],["active","=",True],"|",["last_calculate_rating","=",False],["last_calculate_rating","<","2023-01-01 00:00:00"]] current_time = datetime.now() delta_time = current_time - timedelta(days=30) @@ -141,51 +158,29 @@ class ProductTemplate(models.Model): delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') products = self.env['product.template'].search([ + '&','&', ('type', '=', 'product'), ('active', '=', True), + '|', ('last_calculate_rating', '=', False), + ('last_calculate_rating', '<', delta_time), # ('id', '=', 22798), - ], limit=100) + ], limit=500) for product in products: # print("Calculate Rating Product ", product) _logger.info("Calculate Rating Product %s" % product.id) - product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) + # product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) rate = 0 if product.web_price: rate += 1 - product.web_price_sorting = product.web_price - if product.have_promotion_program: + if product.have_promotion_program: #have discount from pricelist rate += 1 if product.image_128: - rate += 1 - if product.website_description: - rate += 1 - if product_variant.qty_stock_vendor > 0: - rate += 1 - product.product_rating = rate - product.last_calculate_rating = current_time - - products = self.env['product.template'].search([ - ('type', '=', 'product'), - ('active', '=', True), - ('last_calculate_rating', '<', delta_time), - ], limit=100) - - for product in products: - print("Calculate Rating Product OutOfDate", product) - product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) - rate = 0 - if product.web_price: - rate += 1 - product.web_price_sorting = product.web_price - if product.have_promotion_program: - rate += 1 - if product.image_128: - rate += 1 + rate += 5 if product.website_description: rate += 1 - if product_variant.qty_stock_vendor > 0: + if product.product_variant_id.qty_stock_vendor > 0: rate += 1 product.product_rating = rate product.last_calculate_rating = current_time diff --git a/indoteknik_custom/models/raja_ongkir.py b/indoteknik_custom/models/raja_ongkir.py new file mode 100644 index 00000000..fa02a6bf --- /dev/null +++ b/indoteknik_custom/models/raja_ongkir.py @@ -0,0 +1,24 @@ +from odoo import fields, models, api +import logging +import json + +_logger = logging.getLogger(__name__) + +class Kurir(models.Model): + _name = 'rajaongkir.kurir' + + delivery_carrier_id = fields.Many2one('delivery.carrier', String='Odoo Carrier', help='dimapping dengan bawaan delivery carrier di odoo') + name = fields.Char(string='Name', help='nama kurir sesuai dengan data yang ada di API RajaOngkir') + publish = fields.Boolean(string='Publish') + image = fields.Binary(string='Image') + +class State(models.Model): + _inherit = 'res.country.state' + + rajaongkir_id = fields.Integer(string='RajaOngkir_ID', help='mapping dengan rajaongkir berdasarkan ID') + + +class Kota(models.Model): + _inherit = 'vit.kota' + + rajaongkir_id = fields.Integer(string='RajaOngkir_ID', help='mapping dengan rajaongkir berdasarkan ID') diff --git a/indoteknik_custom/models/uangmuka_pembelian.py b/indoteknik_custom/models/uangmuka_pembelian.py index 797d7a01..26a003fd 100644 --- a/indoteknik_custom/models/uangmuka_pembelian.py +++ b/indoteknik_custom/models/uangmuka_pembelian.py @@ -50,11 +50,15 @@ class UangmukaPembelian(models.TransientModel): account_move = request.env['account.move'].create([param_header]) _logger.info('Success Create Uang Muka Pembelian %s' % account_move.name) + if order.partner_id.parent_id: + partner_id = order.partner_id.parent_id.id + else: + partner_id = order.partner_id.id param_debit = { 'move_id': account_move.id, 'account_id': 401, # uang muka persediaan barang dagang - 'partner_id': order.partner_id.id, + 'partner_id': partner_id, 'currency_id': 12, 'debit': self.pay_amt, 'credit': 0, @@ -63,7 +67,7 @@ class UangmukaPembelian(models.TransientModel): param_debit_ongkir = { 'move_id': account_move.id, 'account_id': 536, # biaya ongkos kirim - 'partner_id': order.partner_id.id, + 'partner_id': partner_id, 'currency_id': 12, 'debit': self.ongkir_amt, 'credit': 0, @@ -72,7 +76,7 @@ class UangmukaPembelian(models.TransientModel): param_debit_selisih = { 'move_id': account_move.id, 'account_id': 561, # selisih pembayaran - 'partner_id': order.partner_id.id, + 'partner_id': partner_id, 'currency_id': 12, 'debit': self.selisih_amt, 'credit': 0, @@ -82,7 +86,7 @@ class UangmukaPembelian(models.TransientModel): param_credit = { 'move_id': account_move.id, 'account_id': self.account_id.id, # bank in transit - 'partner_id': order.partner_id.id, + 'partner_id': partner_id, 'currency_id': 12, 'debit': 0, 'credit': self.pay_amt + self.ongkir_amt + self.selisih_amt, diff --git a/indoteknik_custom/models/uangmuka_penjualan.py b/indoteknik_custom/models/uangmuka_penjualan.py index ef0e9196..93a33b52 100644 --- a/indoteknik_custom/models/uangmuka_penjualan.py +++ b/indoteknik_custom/models/uangmuka_penjualan.py @@ -53,11 +53,15 @@ class UangmukaPenjualan(models.TransientModel): account_move = request.env['account.move'].create([param_header]) _logger.info('Success Create Uang Muka Penjualan %s' % account_move.name) + if order.partner_id.parent_id: + partner_id = order.partner_id.parent_id.id + else: + partner_id = order.partner_id.id param_debit = { 'move_id': account_move.id, 'account_id': self.account_id.id, # intransit - 'partner_id': order.partner_id.id, + 'partner_id': partner_id, 'currency_id': 12, 'debit': self.pay_amt + self.ongkir_amt + self.selisih_amt, 'credit': 0, @@ -67,7 +71,7 @@ class UangmukaPenjualan(models.TransientModel): param_credit = { 'move_id': account_move.id, 'account_id': 449, # uang muka penjualan - 'partner_id': order.partner_id.id, + 'partner_id': partner_id, 'currency_id': 12, 'debit': 0, 'credit': self.pay_amt, @@ -76,7 +80,7 @@ class UangmukaPenjualan(models.TransientModel): param_ongkir_credit = { 'move_id': account_move.id, 'account_id': 550, # pendapatan ongkos kirim - 'partner_id': order.partner_id.id, + 'partner_id': partner_id, 'currency_id': 12, 'debit': 0, 'credit': self.ongkir_amt, @@ -85,7 +89,7 @@ class UangmukaPenjualan(models.TransientModel): param_selisih_credit = { 'move_id': account_move.id, 'account_id': 561, # selisih pembayaran - 'partner_id': order.partner_id.id, + 'partner_id': partner_id, 'currency_id': 12, 'debit': 0, 'credit': self.selisih_amt, diff --git a/indoteknik_custom/models/x_banner_banner.py b/indoteknik_custom/models/x_banner_banner.py index bc80e2a9..c34b7634 100755 --- a/indoteknik_custom/models/x_banner_banner.py +++ b/indoteknik_custom/models/x_banner_banner.py @@ -8,6 +8,7 @@ class XBannerBanner(models.Model): x_name = fields.Char(string="Name") x_url_banner = fields.Char(string="URL Banner") + background_color = fields.Char(string="Background Color") x_banner_image = fields.Binary(string="Image") x_banner_category = fields.Many2one('x_banner.category', string="Banner Category") x_relasi_manufacture = fields.Many2one('x_manufactures', string="Relasi Merek") diff --git a/indoteknik_custom/models/x_manufactures.py b/indoteknik_custom/models/x_manufactures.py index dd6948a9..710bfe8a 100755 --- a/indoteknik_custom/models/x_manufactures.py +++ b/indoteknik_custom/models/x_manufactures.py @@ -46,6 +46,15 @@ class XManufactures(models.Model): show_as_new_product = fields.Boolean(string='Show as New Product', help='Centang jika ingin ditammpilkan di website sebagai segment Produk Baru') parent_id = fields.Many2one('x_manufactures', string='Parent', help='Parent Brand tersebut') category_ids = fields.Many2many('product.public.category', string='Category', help='Brand tsb memiliki Category apa saja') + vendor_ids = fields.Many2many('res.partner', string='Vendor', compute='_compute_vendor_ids') + + def _compute_vendor_ids(self): + for manufacture in self: + vendor_ids = [] + brand_vendors = self.env['brand.vendor'].search([('x_manufacture_id', '=', manufacture.id)], order='priority') + for vendor in brand_vendors: + vendor_ids.append(vendor.partner_id.id) + manufacture.vendor_ids = vendor_ids def cache_reset(self): manufactures = self.env['x_manufactures'].search([ |
