diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-11-11 16:10:44 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-11-11 16:10:44 +0700 |
| commit | c8ce7890c7174ea678da282e3fa04501b24951bc (patch) | |
| tree | f007d7bed000bdfa38f64d85af122f1d65b5c565 | |
| parent | 4c2325d4a983ced3a25a9d53d7613a9186360b17 (diff) | |
| parent | 17d46cf9f4eede8177b2373c03d5b36123f712c1 (diff) | |
Merge branch 'production' into iman/request-renca-stock
36 files changed, 793 insertions, 115 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index 2a24b205..7a40b1e2 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -46,8 +46,25 @@ class Cart(controller.Controller): def get_cart_count_by_user_id(self, user_id, **kw): user_id = int(user_id) query = [('user_id', '=', user_id)] - carts = request.env['website.user.cart'].search_count(query) - return self.response(carts) + carts = request.env['website.user.cart'].search(query) + products_active = [] + products_inactive = [] + for cart in carts: + if cart.product_id: + price = cart.product_id._v2_get_website_price_include_tax() + if cart.product_id.active and price > 0: + product = cart.with_context(price_for="web").get_products() + for product_active in product: + products_active.append(product_active) + else: + product_inactives = cart.with_context(price_for="web").get_products() + for inactives in product_inactives: + products_inactive.append(inactives) + else: + program = cart.with_context(price_for="web").get_products() + for programs in program: + products_active.append(programs) + return self.response(len(products_active)) @http.route(PREFIX_USER + 'cart/create-or-update', auth='public', methods=['POST', 'OPTIONS'], csrf=False) @controller.Controller.must_authorized(private=True, private_key='user_id') diff --git a/indoteknik_api/controllers/api_v1/partner.py b/indoteknik_api/controllers/api_v1/partner.py index a7925a02..bbca471b 100644 --- a/indoteknik_api/controllers/api_v1/partner.py +++ b/indoteknik_api/controllers/api_v1/partner.py @@ -74,6 +74,9 @@ class Partner(controller.Controller): 'district_id': ['number', 'alias:kecamatan_id'], 'sub_district_id': ['number', 'alias:kelurahan_id', 'exclude_if_null'], 'zip': ['required'], + 'longtitude': [], + 'latitude': [], + 'address_map': [], 'alamat_lengkap_text': [] }) @@ -105,6 +108,9 @@ class Partner(controller.Controller): 'city_id': ['required', 'number', 'alias:kota_id'], 'district_id': ['number', 'alias:kecamatan_id'], 'sub_district_id': ['number', 'alias:kelurahan_id', 'exclude_if_null'], + 'longtitude': [], + 'latitude': [], + 'address_map': [], 'zip': ['required'] }) diff --git a/indoteknik_api/controllers/api_v1/stock_picking.py b/indoteknik_api/controllers/api_v1/stock_picking.py index 8b941c16..ea8c6400 100644 --- a/indoteknik_api/controllers/api_v1/stock_picking.py +++ b/indoteknik_api/controllers/api_v1/stock_picking.py @@ -1,6 +1,8 @@ from .. import controller from odoo import http from odoo.http import request +from pytz import timezone +from datetime import datetime class StockPicking(controller.Controller): @@ -110,4 +112,26 @@ class StockPicking(controller.Controller): if not picking: return self.response(None) - return self.response(picking.get_tracking_detail())
\ No newline at end of file + return self.response(picking.get_tracking_detail()) + + @http.route(prefix + 'stock-picking/<picking_code>/documentation', auth='public', methods=['PUT', 'OPTIONS'], csrf=False) + @controller.Controller.must_authorized() + def write_partner_stock_picking_documentation(self, **kw): + picking_code = int(kw.get('picking_code', 0)) + sj_document = kw.get('sj_document', False) + paket_document = kw.get('paket_document', False) + + params = {'sj_documentation': sj_document, + 'paket_documentation': paket_document, + 'driver_arrival_date': datetime.utcnow(), + } + + picking_data = request.env['stock.picking'].search([('picking_code', '=', picking_code)], limit=1) + + if not picking_data: + return self.response(code=404, description='picking not found') + picking_data.write(params) + + return self.response({ + 'name': picking_data.name + })
\ No newline at end of file diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index c7bfe91a..3be874fa 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -95,7 +95,7 @@ class User(controller.Controller): user = request.env['res.users'].create(user_data) user.partner_id.email = email user.partner_id.customer_type = 'nonpkp' - user.partner_id.npwp = '0.000.000.0-000.000' + user.partner_id.npwp = '00.000.000.0-000.000' user.partner_id.sppkp = '-' user.partner_id.nama_wajib_pajak = user.name user.partner_id.user_id = 3222 @@ -248,7 +248,7 @@ class User(controller.Controller): if type_acc == 'individu': user.partner_id.customer_type = 'nonpkp' - user.partner_id.npwp = '0.000.000.0-000.000' + user.partner_id.npwp = '00.000.000.0-000.000' user.partner_id.sppkp = '-' user.partner_id.nama_wajib_pajak = name user.partner_id.user_id = 3222 diff --git a/indoteknik_api/models/res_users.py b/indoteknik_api/models/res_users.py index 534898e1..230707cb 100644 --- a/indoteknik_api/models/res_users.py +++ b/indoteknik_api/models/res_users.py @@ -48,7 +48,7 @@ class ResUsers(models.Model): 'street': user.street or '', 'street2': user.street2 or '', 'city': None, - 'state_id': None, + 'state_id': 0, 'district': None, 'sub_district': None, 'zip': user.zip or '', @@ -59,6 +59,9 @@ class ResUsers(models.Model): 'rajaongkir_city_id': user.kecamatan_id.rajaongkir_id or 0, 'alamat_wajib_pajak': user.alamat_lengkap_text or None, 'alamat_bisnis': user.street or None, + 'longtitude': user.longtitude or None, + 'latitude': user.latitude or None, + 'address_map': user.address_map or None, } if user.state_id: diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 116c64ec..c8a658b5 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -144,6 +144,7 @@ 'views/vendor_payment_term.xml', 'views/approval_unreserve.xml', 'views/vendor_approval.xml', + 'views/find_page.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 7b41a5fe..e62fbb4a 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -130,3 +130,4 @@ from . import account_tax from . import approval_unreserve from . import vendor_approval from . import partner +from . import find_page diff --git a/indoteknik_custom/models/account_move_due_extension.py b/indoteknik_custom/models/account_move_due_extension.py index 23f8888c..6fc58cdd 100644 --- a/indoteknik_custom/models/account_move_due_extension.py +++ b/indoteknik_custom/models/account_move_due_extension.py @@ -1,6 +1,6 @@ from odoo import models, api, fields from odoo.exceptions import AccessError, UserError, ValidationError -from datetime import timedelta, date +from datetime import timedelta, date, datetime import logging _logger = logging.getLogger(__name__) @@ -31,7 +31,8 @@ class DueExtension(models.Model): ('21', '21 Hari'), ], string='Day Extension', help='Menambah Due Date yang sudah limit dari hari ini', tracking=True) counter = fields.Integer(string="Counter", compute='_compute_counter') - + approve_by = fields.Many2one('res.users', string="Approve By", readonly=True) + date_approve = fields.Datetime(string="Date Approve", readonly=True) def _compute_counter(self): for due in self: due.counter = due.partner_id.counter @@ -96,6 +97,8 @@ class DueExtension(models.Model): sales.action_confirm() self.order_id.due_id = self.id + self.approve_by = self.env.user.id + self.date_approve = datetime.utcnow() template = self.env.ref('indoteknik_custom.mail_template_due_extension_approve') template.send_mail(self.id, force_send=True) diff --git a/indoteknik_custom/models/approval_date_doc.py b/indoteknik_custom/models/approval_date_doc.py index 441ada3d..751bae82 100644 --- a/indoteknik_custom/models/approval_date_doc.py +++ b/indoteknik_custom/models/approval_date_doc.py @@ -40,6 +40,7 @@ class ApprovalDateDoc(models.Model): raise UserError("Hanya Accounting Yang Bisa Approve") self.check_invoice_so_picking self.picking_id.driver_departure_date = self.driver_departure_date + self.picking_id.date_doc_kirim = self.driver_departure_date self.state = 'done' self.approve_date = datetime.utcnow() self.approve_by = self.env.user.id diff --git a/indoteknik_custom/models/approval_unreserve.py b/indoteknik_custom/models/approval_unreserve.py index 88409c37..ba8b8da7 100644 --- a/indoteknik_custom/models/approval_unreserve.py +++ b/indoteknik_custom/models/approval_unreserve.py @@ -31,12 +31,12 @@ class ApprovalUnreserve(models.Model): if not self.picking_id: raise ValidationError("Picking is required") - stock_move = self.env['stock.move'].search([('picking_id', '=', self.picking_id.id), ('state', '=', 'assigned')]) + stock_move = self.env['stock.move'].search([('picking_id', '=', self.picking_id.id), ('state', 'in', ['assigned', 'partially_available'])]) if not stock_move: raise ValidationError("Picking is not found") - for move in stock_move: + for move in stock_move: self.approval_line.create({ 'approval_id': self.id, 'move_id': move.id @@ -68,13 +68,13 @@ class ApprovalUnreserve(models.Model): if not move: raise UserError("Product tidak ada di destination picking") - qty_unreserve = line.unreserve_qty + move.forecast_availability + qty_unreserve = line.unreserve_qty + move.reserved_availability if move.product_uom_qty < qty_unreserve: raise UserError("Quantity yang di unreserve melebihi quantity yang ada") def action_approve(self): - if self.env.user.id != self.user_id.id: + if self.env.user.id != self.user_id.id and not self.env.user.has_group('indoteknik_custom.group_role_it'): raise UserError("Hanya Sales nya yang bisa approve.") if self.state != 'waiting_approval': @@ -86,6 +86,7 @@ class ApprovalUnreserve(models.Model): }) # Trigger the unreserve function self._trigger_unreserve() + self.picking_id.check_state_reserve() def action_reject(self, reason): if self.env.user.id != self.user_id.id: diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index b0d3430c..078d9810 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -31,6 +31,8 @@ class CrmLead(models.Model): if rec.email_from == 'api.noreply@altama.co.id' and rec.name.startswith('INDOTEKNIK|ODOO|'): rec.user_id = 20 # User ID: Nabila Rahmawati + if not rec.user_id: + rec.user_id = 2 # User ID: Sales return rec @api.onchange('user_id') @@ -98,7 +100,27 @@ class CrmLead(models.Model): lead.user_id = salesperson_id - def _cancel_pipeline(self, delta=48): + def _update_pipeline(self, delta=48, limit=100): + # Get the current time + current_time = datetime.now() + + # Calculate the time 24 hours ago + time_48_hours_ago = current_time - timedelta(hours=delta) + + # Define the allowed states + allowed_states = ['sale', 'done'] + + # Search for sale orders with date_order greater than 24 hours ago and opportunity_id is null + orders = self.env['sale.order'].search([ + ('write_date', '>=', time_48_hours_ago), + ('opportunity_id', '!=', False), + ('state', 'in', allowed_states) + ], limit=limit) + for order in orders: + order.opportunity_id.stage_id = 4 + _logger.info('finish order stage pipeline %s' % order.id) + + def _cancel_pipeline(self, delta=48, limit=100): # Get the current time current_time = datetime.now() @@ -113,12 +135,12 @@ class CrmLead(models.Model): ('write_date', '>=', time_48_hours_ago), ('opportunity_id', '!=', False), ('state', 'in', allowed_states) - ]) + ], limit=limit) for order in orders: order.opportunity_id.stage_id = 7 _logger.info('cancel order stage pipeline %s' % order.id) - def _convert_to_pipeline(self, delta=48): + def _convert_to_pipeline(self, delta=48, limit=100): # Get the current time current_time = datetime.now() @@ -133,7 +155,7 @@ class CrmLead(models.Model): ('write_date', '>=', time_48_hours_ago), ('opportunity_id', '=', False), ('state', 'in', allowed_states) - ]) + ], limit=limit) # stage # 1 potensi baru, 2 proses quotation, 3 proses lain visit, 4 proses berhasil, 5 proses negosiasi, 7 tidak terpakai / gagal for order in orders: diff --git a/indoteknik_custom/models/delivery_order.py b/indoteknik_custom/models/delivery_order.py index be5fd2e0..3473197b 100644 --- a/indoteknik_custom/models/delivery_order.py +++ b/indoteknik_custom/models/delivery_order.py @@ -33,11 +33,13 @@ class DeliveryOrder(models.TransientModel): picking.driver_id = self.env.uid picking.delivery_tracking_no = line_tracking_no + if picking.driver_departure_date: + picking.sj_return_date = datetime.utcnow() + delivery_type = self.env['delivery.order.line'].get_delivery_type(picking.driver_departure_date, picking.driver_arrival_date) if delivery_type == 'departure': picking.driver_departure_date = current_time elif delivery_type == 'arrival': - picking.driver_arrival_date = current_time sale_order = False if picking.origin: @@ -103,14 +105,16 @@ class DeliveryOrderLine(models.TransientModel): delivery_type = self.get_delivery_type(picking.driver_departure_date, picking.driver_arrival_date) if delivery_type != 'departure': - self.departure_date = picking.driver_departure_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') + if picking.driver_departure_date: + self.departure_date = picking.driver_departure_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') if delivery_type == 'departure': self.departure_date = current_time elif delivery_type == 'arrival': self.arrival_date = current_time else: - self.arrival_date = picking.driver_arrival_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') + if picking.driver_arrival_date: + self.arrival_date = picking.driver_arrival_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') else: raise UserError('Nomor DO tidak ditemukan') diff --git a/indoteknik_custom/models/find_page.py b/indoteknik_custom/models/find_page.py new file mode 100644 index 00000000..467e30d1 --- /dev/null +++ b/indoteknik_custom/models/find_page.py @@ -0,0 +1,121 @@ +from odoo import fields, models, api, tools, _ +import logging +import re +import pysolr + +_logger = logging.getLogger(__name__) +_cat_brand_solr = pysolr.Solr('http://10.148.0.5:8983/solr/url_category_brand/', always_commit=True, timeout=30) +# _cat_brand_solr_dev = pysolr.Solr('http://127.0.0.1:8983/solr/url_category_brand/', always_commit=True, timeout=30) + + +class BrandProductCategory(models.Model): + _name = 'v.brand.product.category' + _auto = False + _rec_name = 'brand_id' + brand_id = fields.Many2one('x_manufactures', string='Brand') + category_id = fields.Many2one('product.public.category', string='Category') + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW %s + AS select row_number() over(order by pt.x_manufacture) as id, + pt.x_manufacture as brand_id, + ppcptr.product_public_category_id as category_id + from product_template pt + join product_public_category_product_template_rel ppcptr on ppcptr.product_template_id = pt.id + join x_manufactures xm on xm.id = pt.x_manufacture + group by x_manufacture, ppcptr.product_public_category_id + """ % self._table) + + +class FindPage(models.Model): + _name = 'web.find.page' + _inherit = ['mail.thread'] + _rec_name = 'url' + + brand_id = fields.Many2one('x_manufactures', string='Brand') + category_id = fields.Many2one('product.public.category', string='Category', help='Bisa semua level Category') + url = fields.Char(string='Url') + + def _sync_to_solr(self, limit=10000): + urls = self.env['web.find.page'].search([]) + documents = [] + catch = {} + for url in urls: + try: + document = { + 'id': url.id, + 'category_id_i': url.category_id.id, + 'brand_id_i': url.brand_id.id, + 'url_s': url.url + } + documents.append(document) + catch = document + except Exception as e: + _logger.error('Failed to add document to Solr URL Category Brand: %s', e) + _logger.error('Document Data: %s', catch) + _cat_brand_solr.add(documents) + return True + + def _get_category_hierarchy(self, category): + categories = [] + current_category = category + while current_category: + categories.insert(0, current_category) + current_category = current_category.parent_id + return categories + + def _generate_url(self): + categories = self.env['v.brand.product.category'].search([]) + + list_url = [] + for category in categories: + category_hierarchy = self._get_category_hierarchy(category.category_id) + + for level, cat in enumerate(reversed(category_hierarchy), start=1): + list_url.append(self._generate_mod_url(cat, category.brand_id)) + # print(f"Level {level}: {cat.name} {category.brand_id.x_name}") + + unique_list = [] + for item in list_url: + if item not in unique_list: + unique_list.append(item) + count = 0 + for item in unique_list: + self._create_find_page(item['url'], item['category_id'], item['brand_id']) + count += 1 + print(f"Total categories processed: {count}") + + def _create_find_page(self, url, category_id, brand_id): + param = { + 'url': url, + 'category_id': category_id, + 'brand_id': brand_id, + } + find_page = self.env['web.find.page'].create(param) + _logger.info('Created Web Find Page %s' % find_page.id) + + def _generate_mod_url(self, category, brand): + # generate_url = 'https://indoteknik.com/shop/find/category-brand' example + cleaned_category = re.sub(r'[^\w\s]', '', category.name) + cleaned_brand = re.sub(r'[^\w\s]', '', brand.x_name) + cleaned_combined = cleaned_category+' '+cleaned_brand + cleaned_combined = cleaned_combined.replace(' ', '-') + cleaned_combined = cleaned_combined.replace('--', '-') + url = 'https://indoteknik.com/shop/find/'+cleaned_combined + url = url.lower() + result = { + 'url': url, + 'category_id': category.id, + 'brand_id': brand.id + } + # print(url) + # param = { + # 'brand_id': brand.id, + # 'category_id': category.id, + # 'url':'' + # } + # self.env['web.find.page'].create() + # print(1) + return result diff --git a/indoteknik_custom/models/logbook_sj.py b/indoteknik_custom/models/logbook_sj.py index f84619ad..9f349882 100644 --- a/indoteknik_custom/models/logbook_sj.py +++ b/indoteknik_custom/models/logbook_sj.py @@ -101,14 +101,16 @@ class LogbookSJLine(models.TransientModel): delivery_type = self.get_delivery_type(picking.driver_departure_date, picking.driver_arrival_date) if delivery_type != 'departure': - self.departure_date = picking.driver_departure_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') + if picking.driver_departure_date: + self.departure_date = picking.driver_departure_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') if delivery_type == 'departure': self.departure_date = current_time elif delivery_type == 'arrival': self.arrival_date = current_time else: - self.arrival_date = picking.driver_arrival_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') + if picking.driver_arrival_date: + self.arrival_date = picking.driver_arrival_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') else: raise UserError('Nomor DO tidak ditemukan') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index af7f98cd..e64b63d7 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -389,22 +389,46 @@ class ProductProduct(models.Model): @api.constrains('active') def archive_product(self): for product in self: + if self.env.context.get('skip_unpublished_constraint'): + continue # Mencegah looping saat dipanggil dari metode lain + product_template = product.product_tmpl_id variants = product_template.product_variant_ids - if product_template.active and product.active: - if not product.active and len(variants) == 1: - product_template.with_context(skip_active_constraint=True).active = False - product_template.unpublished = True - elif not product.active and len(variants) > 1: + if len(variants) == 1: + # Jika hanya ada satu varian, atur status `unpublished` berdasarkan `active` + product_template.with_context(skip_unpublished_constraint=True).unpublished = not product.active + product.with_context(skip_unpublished_constraint=True).unpublished = not product.active + else: + if product.active: + product.with_context(skip_unpublished_constraint=True).unpublished = False + product_template.with_context(skip_unpublished_constraint=True).unpublished = any(variant.active for variant in variants) + else: + product.with_context(skip_unpublished_constraint=True).unpublished = True all_inactive = all(not variant.active for variant in variants) - if all_inactive: - product_template.with_context(skip_active_constraint=True).active = False - product_template.unpublished = True - else: - continue - if any(variant.active for variant in variants): - product_template.unpublished = False + product_template.with_context(skip_unpublished_constraint=True).unpublished = all_inactive + + @api.constrains('unpublished') + def archive_product_unpublished(self): + for product in self: + if self.env.context.get('skip_active_constraint'): + continue # Mencegah looping saat dipanggil dari metode lain + + product_template = product.product_tmpl_id + variants = product_template.product_variant_ids + + if len(variants) == 1: + # Jika hanya ada satu varian, atur status `unpublished` pada template, tetapi biarkan `active` tetap True + product_template.with_context(skip_active_constraint=True).unpublished = product.unpublished + else: + if not product.unpublished: + # Jika `unpublished` adalah False, pastikan `active` tetap True + product.with_context(skip_active_constraint=True).active = True + product_template.with_context(skip_active_constraint=True).active = any(not variant.unpublished for variant in variants) + else: + # Jika `unpublished` adalah True, atur template hanya jika semua varian di-unpublished + all_unpublished = all(variant.unpublished for variant in variants) + product_template.with_context(skip_active_constraint=True).active = not all_unpublished def update_internal_reference_variants(self, limit=100): variants = self.env['product.product'].search([ diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 340df49e..ef86bc61 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -68,6 +68,7 @@ class PurchaseOrder(models.Model): ], string='Printed?', copy=False, tracking=True) date_done_picking = fields.Datetime(string='Date Done Picking', compute='get_date_done') bills_dp_id = fields.Many2one('account.move', string='Bills DP') + bills_pelunasan_id = fields.Many2one('account.move', string='Bills Pelunasan') grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') total_margin_match = fields.Float(string='Total Margin Match', compute='_compute_total_margin_match') approve_by = fields.Many2one('res.users', string='Approve By') @@ -89,6 +90,89 @@ class PurchaseOrder(models.Model): else: order.grand_total = order.amount_total + def create_bill_pelunasan(self): + if not self.env.user.is_accounting: + raise UserError('Hanya Accounting yang bisa bikin bill dp') + + # Check for existing vendor bills with the same reference and partner + existing_bill = self.env['account.move'].search([ + ('ref', '=', self.name), + ('partner_id', '=', self.partner_id.id), + ('move_type', '=', 'in_invoice'), + ('state', 'not in', ['cancel', 'posted']) + ], limit=1) + + if existing_bill: + raise UserError(_('Duplicated vendor reference detected. You probably encoded twice the same vendor bill/credit note: %s') % existing_bill.name) + + current_date = datetime.utcnow() + data_bills = { + 'partner_id': self.partner_id.id, + 'partner_shipping_id': self.partner_id.id, + 'ref': self.name, + 'invoice_date': current_date, + 'date': current_date, + 'move_type': 'in_invoice' + } + + bills = self.env['account.move'].create([data_bills]) + + product_dp = self.env['product.product'].browse(229625) + + data_line_bills = [] + + move_line = self.env['account.move.line'].search([ + ('move_id', '=', self.bills_dp_id.id), + ('product_id', '=', product_dp.id), + ]) + + bills.message_post( + body=f"<div>" + f"<b>DP :</b><br>{move_line.price_unit}</div>", + subtype_id=self.env.ref("mail.mt_note").id + ) + + data_line_bills.append({ + 'move_id': bills.id, + 'product_id': product_dp.id, # product down payment + 'name': '[IT.121456] Down Payment', # product down payment + 'account_id': 401, # Uang Muka persediaan barang dagang + # 'price_unit': move_line.price_unit, + 'quantity': -1, + 'product_uom_id': 1, + 'tax_ids': [(5, 0, 0)] + [(4, tax.id) for tax in product_dp.taxes_id], + }) + + for line in self.order_line: + if line.product_id: + data_line_bills.append({ + 'move_id': bills.id, + 'product_id': line.product_id.id, + 'name': self.name + ": " + line.product_id.display_name, + 'account_id': 439, # Uang Muka persediaan barang dagang + 'quantity': line.product_qty, + # 'price_unit': line.price_subtotal, + 'product_uom_id': line.product_uom.id, + 'tax_ids': [(5, 0, 0)] + [(4, tax.id) for tax in line.taxes_id], + 'purchase_line_id': line.id, + 'purchase_order_id': line[0].order_id.id, + }) + + bills_line = self.env['account.move.line'].create(data_line_bills) + + self.bills_pelunasan_id = bills.id + + return { + 'name': _('Account Move'), + 'view_mode': 'tree,form', + 'res_model': 'account.move', + 'target': 'current', + 'type': 'ir.actions.act_window', + 'domain': [('id', '=', bills.id)] + } + + + def create_bill_dp(self): if not self.env.user.is_accounting: raise UserError('Hanya Accounting yang bisa bikin bill dp') @@ -508,11 +592,11 @@ class PurchaseOrder(models.Model): if self.amount_untaxed >= 50000000 and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser'): raise UserError("Hanya Merchandiser yang bisa approve") - if self.total_percent_margin < self.total_so_percent_margin and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: - raise UserError("Beda Margin dengan Sales, harus approval Manager") + if self.total_percent_margin < self.total_so_percent_margin and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser') and not self.env.user.is_leader: + raise UserError("Beda Margin dengan Sales, harus approval Merchandise") if not self.from_apo: - if not self.sale_order_id and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: - raise UserError("Tidak ada link dengan SO, harus approval Manager") + if not self.matches_so and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser') and not self.env.user.is_leader: + raise UserError("Tidak ada link dengan SO, harus approval Merchandise") send_email = False self.add_product_to_pricelist() @@ -641,12 +725,27 @@ class PurchaseOrder(models.Model): def po_approve(self): if self.amount_untaxed >= 50000000 and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser'): raise UserError("Hanya Merchandiser yang bisa approve") - if self.env.user.is_leader or self.env.user.is_purchasing_manager: + if self.env.user.is_leader or self.env.user.has_group('indoteknik_custom.group_role_merchandiser'): raise UserError("Bisa langsung Confirm") - elif self.total_percent_margin == self.total_so_percent_margin and self.sale_order_id: + elif self.total_percent_margin == self.total_so_percent_margin and self.matches_so: raise UserError("Bisa langsung Confirm") else: + reason = '' self.approval_status = 'pengajuan1' + if self.amount_untaxed >= 50000000: + reason = 'above 50jt, ' + if self.total_percent_margin < self.total_so_percent_margin: + reason += 'diff margin, ' + if not self.from_apo and not self.matches_so: + reason += 'not link with pj and reorder, ' + if not self.matches_so: + reason += 'not link with so, ' + # Post a highlighted message to lognote + self.message_post( + body=f"<div style='background-color: #fdf2e9; border: 1px solid #f5c6cb; padding: 10px;'>" + f"<b>Note (Pinned):</b><br>{reason}</div>", + subtype_id=self.env.ref("mail.mt_note").id + ) def re_calculate(self): if self.from_apo: diff --git a/indoteknik_custom/models/report_stock_forecasted.py b/indoteknik_custom/models/report_stock_forecasted.py index 5f9427f8..ebdc7d4a 100644 --- a/indoteknik_custom/models/report_stock_forecasted.py +++ b/indoteknik_custom/models/report_stock_forecasted.py @@ -33,7 +33,6 @@ class ReplenishmentReport(models.AbstractModel): 'reserved_from': result, 'qty_fullfillment': quantity, }) - return lines def _calculate_result(self, line): diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index 2b148c96..3d9ca876 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -1,4 +1,4 @@ -from odoo import models, fields, api, _ +from odoo import models, fields, api, tools, _ from odoo.exceptions import UserError from datetime import datetime import math @@ -7,6 +7,33 @@ import logging _logger = logging.getLogger(__name__) +class RequisitionMatchPO(models.Model): + _name = 'v.requisition.match.po' + _auto = False + _rec_name = 'product_id' + + id = fields.Integer(string='ID') + product_id = fields.Many2one('product.product', string='Product') + qty_rpo = fields.Float(string='Qty RPO', help='Qty RPO yang sudah di PO namun SO masih Draft') + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + create or replace view %s as + select rl.product_id as id, rl.product_id, sum(rl.qty_purchase) as qty_rpo + from requisition_line rl + join requisition r on r.id = rl.requisition_id + join requisition_purchase_match rpm on rpm.requisition_id = r.id + join purchase_order po on po.id = rpm.order_id + join sale_order so on so.id = r.sale_order_id + where 1=1 + and r.date_doc >= '2024-11-11' + and po.state in ('done', 'purchase') + and so.state in ('draft', 'sent') + group by rl.product_id + """ % self._table) + + class Requisition(models.Model): _name = 'requisition' _order = 'id desc' @@ -22,19 +49,36 @@ class Requisition(models.Model): requisition_match = fields.One2many('requisition.purchase.match', 'requisition_id', string='Matches', auto_join=True) sale_order_id = fields.Many2one('sale.order', string='SO', help='harus diisi nomor SO yang ingin digenerate', domain="[('state', '=', 'sale')]") + sales_approve = fields.Boolean(string='Sales Approve', tracking=3, copy=False) + merchandise_approve = fields.Boolean(string='Merchandise Approve', tracking=3, copy=False) @api.model def create(self, vals): vals['number'] = self.env['ir.sequence'].next_by_code('requisition') or '0' result = super(Requisition, self).create(vals) return result - + + def button_approve(self): + if self.env.user.id not in [377, 19]: + raise UserError('Hanya Vita dan Darren Yang Bisa Approve') + if self.env.user.id == 377: + self.sales_approve = True + elif self.env.user.id == 19: + if not self.sales_approve: + raise UserError('Vita Belum Approve') + self.merchandise_approve = True def create_po_from_requisition(self): + if not self.sales_approve: + raise UserError('Harus di Approve Vita') + if not self.merchandise_approve: + raise UserError('Harus di Approve Darren') if not self.requisition_lines: raise UserError('Tidak ada Lines, belum bisa create PO') if self.is_po: raise UserError('Sudah pernah di create PO') + if self.sale_order_id: + raise UserError('Tidak ada link dengan Sales Order, tidak bisa dihitung sebagai Plafon Qty di PO') vendor_ids = self.env['requisition.line'].read_group([ ('requisition_id', '=', self.id), @@ -108,6 +152,13 @@ class Requisition(models.Model): new_po_line = self.env['purchase.order.line'].create([param_line]) line.current_po_id = new_po.id line.current_po_line_id = new_po_line.id + + self.env['requisition.purchase.match'].create([{ + 'requisition_id': self.id, + 'order_id': new_po.id + }]) + self.is_po = True + return po_ids # def create_po_from_requisition(self): @@ -214,6 +265,7 @@ class RequisitionLine(models.Model): last_price = fields.Float(string='Last Price') last_order_id = fields.Many2one('purchase.order', string='Last Order') last_orderline_id = fields.Many2one('purchase.order.line', string='Last Order Line') + taxes_id = fields.Many2one('account.tax', string='Tax') is_po = fields.Boolean(String='Is PO') current_po_id = fields.Many2one('purchase.order', string='Current') current_po_line_id = fields.Many2one('purchase.order.line', string='Current Line') @@ -221,6 +273,23 @@ class RequisitionLine(models.Model): qty_available_store = fields.Float(string='Available') suggest = fields.Char(string='Suggest') + def _get_valid_purchase_price(self, purchase_price): + price = 0 + taxes = '' + human_last_update = purchase_price.human_last_update or datetime.min + system_last_update = purchase_price.system_last_update or datetime.min + + if purchase_price.taxes_product_id.type_tax_use == 'purchase': + price = purchase_price.product_price + taxes = purchase_price.taxes_product_id.id + + if system_last_update > human_last_update: + if purchase_price.taxes_system_id.type_tax_use == 'purchase': + price = purchase_price.system_price + taxes = purchase_price.taxes_system_id.id + + return price, taxes + @api.onchange('price_unit') def _onchange_price_unit(self): for line in self: @@ -230,6 +299,15 @@ class RequisitionLine(models.Model): def _onchange_product(self): for line in self: line.brand_id = line.product_id.product_tmpl_id.x_manufacture.id + purchase_pricelist = self.env['purchase.pricelist'].search([ + ('product_id', '=', line.product_id.id) + ],order='count_trx_po desc, count_trx_po_vendor desc', limit=1) + + price, taxes = line._get_valid_purchase_price(purchase_pricelist) + line.price_unit = price + line.taxes_id = taxes + line.partner_id = purchase_pricelist.vendor_id.id + class RequisitionPurchaseMatch(models.Model): _name = 'requisition.purchase.match' diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 25db16d0..b01c7984 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -48,6 +48,12 @@ class ResPartner(models.Model): date_payment_terms_sales = fields.Datetime(string='Date Update Payment Terms') user_payment_terms_purchase = fields.Many2one('res.users', string='Users Update Payment Terms') date_payment_terms_purchase = fields.Datetime(string='Date Update Payment Terms') + longtitude = fields.Char(string='Longtitude') + latitude = fields.Char(string='Latitude') + address_map = fields.Char(string='Address Map') + company_type = fields.Selection(string='Company Type', + selection=[('person', 'Individual'), ('company', 'Company')], + compute='_compute_company_type', inverse='_write_company_type', tracking=3) @api.model def _default_payment_term(self): diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index e6382cd9..5545e28c 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -78,7 +78,7 @@ class SaleOrder(models.Model): payment_link_midtrans = fields.Char(string='Payment Link', help='Url payment yg digenerate oleh midtrans, harap diserahkan ke customer agar dapat dilakukan pembayaran secara mandiri') payment_qr_code = fields.Binary("Payment QR Code") due_id = fields.Many2one('due.extension', string="Due Extension", readonly=True, tracking=True) - vendor_approval_id = fields.Many2one('vendor.approval', string="Vendor Approval", readonly=True, tracking=True) + vendor_approval_id = fields.Many2one('vendor.approval', string="Vendor Approval", readonly=True, tracking=True, copy=False) customer_type = fields.Selection([ ('pkp', 'PKP'), ('nonpkp', 'Non PKP') @@ -136,6 +136,12 @@ class SaleOrder(models.Model): domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", tracking=True) total_weight = fields.Float(string='Total Weight', compute='_compute_total_weight') + pareto_status = fields.Selection([ + ('PR', 'Pareto Repeating'), + ('PPR', 'Potensi Pareto Repeating'), + ('PNR', 'Pareto Non Repeating'), + ('NP', 'Non Pareto') + ]) def _compute_total_weight(self): total_weight = 0 @@ -642,6 +648,7 @@ class SaleOrder(models.Model): self.sppkp = parent_id.sppkp self.customer_type = parent_id.customer_type self.email = parent_id.email + self.pareto_status = parent_id.pareto_status @api.onchange('partner_id') def onchange_partner_id(self): @@ -761,7 +768,28 @@ class SaleOrder(models.Model): self._validate_order() for order in self: order.order_line.validate_line() + order.check_data_real_delivery_address() + order._validate_order() + order.sale_order_check_approve() + + main_parent = order.partner_id.get_main_parent() + SYSTEM_UID = 25 + FROM_WEBSITE = order.create_uid.id == SYSTEM_UID + + if FROM_WEBSITE and main_parent.use_so_approval and order.web_approval not in ['cust_procurement','cust_director']: + raise UserError("This order not yet approved by customer procurement or director") + + if not order.client_order_ref and order.create_date > datetime(2024, 6, 27): + raise UserError("Customer Reference kosong, di isi dengan NO PO jika PO tidak ada mohon ditulis Tanpa PO") + if not order.commitment_date and order.create_date > datetime(2024, 9, 12): + raise UserError("Expected Delivery Date kosong, wajib diisi") + + if not order.real_shipping_id: + UserError('Real Delivery Address harus di isi') + + if order.validate_partner_invoice_due(): + return self._create_notification_action('Notification','Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') term_days = 0 for term_line in order.payment_term_id.line_ids: @@ -866,14 +894,16 @@ class SaleOrder(models.Model): }).send() def validate_different_vendor(self): - different_vendor = self.order_line.filtered(lambda l: l.vendor_id and l.vendor_md_id and l.vendor_id.id != l.vendor_md_id.id) - if self.vendor_approval_id and self.vendor_approval_id.state == 'draft': raise UserError('SO ini sedang dalam review Vendor Approval') if self.vendor_approval_id and self.vendor_approval_id.state == 'cancel': raise UserError('Vendor Approval SO ini Di Reject') + if self.vendor_approval_id and self.vendor_approval_id.state == 'done': + return False + + different_vendor = self.order_line.filtered(lambda l: l.vendor_id and l.vendor_md_id and l.vendor_id.id != l.vendor_md_id.id) if different_vendor: vendor_approval = self.env['vendor.approval'].create({ 'order_id': self.id, @@ -1307,7 +1337,7 @@ class SaleOrder(models.Model): def create(self, vals): # Ensure partner details are updated when a sale order is created order = super(SaleOrder, self).create(vals) - order._update_partner_details() + # order._update_partner_details() return order def write(self, vals): @@ -1315,8 +1345,8 @@ class SaleOrder(models.Model): res = super(SaleOrder, self).write(vals) # Check if the update is coming from a save operation - if any(field in vals for field in ['sppkp', 'npwp', 'email', 'customer_type']): - self._update_partner_details() + # if any(field in vals for field in ['sppkp', 'npwp', 'email', 'customer_type']): + # self._update_partner_details() return res diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 964b3ff2..5a6640ec 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -252,12 +252,9 @@ class SaleOrderLine(models.Model): # purchase_price = self.env['purchase.pricelist'].search( # query, limit=1, order='count_trx_po desc, count_trx_po_vendor desc') price, taxes, vendor_id = self._get_purchase_price(line.product_id) - line.vendor_md_id = vendor_id line.vendor_id = vendor_id - line.margin_md = line.item_percent_margin line.tax_id = line.order_id.sales_tax_id # price, taxes = line._get_valid_purchase_price(purchase_price) - line.purchase_price_md = price line.purchase_price = price line.purchase_tax_id = taxes @@ -271,6 +268,14 @@ class SaleOrderLine(models.Model): line.name = line_name line.weight = line.product_id.weight + @api.constrains('vendor_id') + def _check_vendor_id(self): + for line in self: + price, taxes, vendor_id = self._get_purchase_price(line.product_id) + line.vendor_md_id = vendor_id if vendor_id else None + line.margin_md = line.item_percent_margin + line.purchase_price_md = price + def compute_delivery_amt_line(self): for line in self: try: diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 7c10a910..dd1d40f6 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -67,6 +67,7 @@ class ProductProduct(models.Model): 'product_id_i': variant.id, 'template_id_i': variant.product_tmpl_id.id, 'image_s': ir_attachment.api_image('product.template', 'image_512', variant.product_tmpl_id.id), + 'image_mobile_s': ir_attachment.api_image('product.template', 'image_256', variant.product_tmpl_id.id), 'stock_total_f': variant.qty_stock_vendor, 'weight_f': variant.weight, 'manufacture_id_i': variant.product_tmpl_id.x_manufacture.id or 0, diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 1d54cc9b..87e8370f 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -91,6 +91,7 @@ class ProductTemplate(models.Model): "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), + 'image_mobile_s': self.env['ir.attachment'].api_image('product.template', 'image_256', template.id), "variant_total_i": template.product_variant_count, "stock_total_f": template.qty_stock_vendor, "weight_f": template.weight, diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 14190474..1906dae0 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -3,7 +3,7 @@ from odoo.exceptions import AccessError, UserError, ValidationError from odoo.tools.float_utils import float_is_zero from datetime import datetime from itertools import groupby -import pytz, datetime +import pytz, datetime, requests, json class StockPicking(models.Model): @@ -25,7 +25,7 @@ class StockPicking(models.Model): # Delivery Order driver_departure_date = fields.Datetime( - string='Driver Departure Date', + string='Delivery Departure Date', copy=False ) arrival_time = fields.Datetime( @@ -33,7 +33,7 @@ class StockPicking(models.Model): copy=False ) driver_arrival_date = fields.Datetime( - string='Driver Arrival Date', + string='Delivery Arrival Date', readonly=True, copy=False ) @@ -53,6 +53,10 @@ class StockPicking(models.Model): readonly=True, copy=False ) + sj_documentation = fields.Binary(string="Dokumentasi Surat Jalan", ) + paket_documentation = fields.Binary(string="Dokumentasi Paket", ) + sj_return_date = fields.Datetime(string="SJ Return Date", ) + responsible = fields.Many2one('res.users', string='Responsible', tracking=True) approval_status = fields.Selection([ ('pengajuan1', 'Approval Accounting'), @@ -73,10 +77,8 @@ class StockPicking(models.Model): ('hold', 'Hold by Sales'), ('not_paid', 'Customer belum bayar'), ('partial', 'Kirim Parsial'), - ('not_complete', 'Belum Lengkap'), ('indent', 'Indent'), ('self_pickup', 'Barang belum di pickup Customer'), - ('delivery_route', 'Belum masuk rute pengiriman'), ('expedition_closed', 'Eskpedisi belum buka') ], string='Note Logistic', help='jika field ini diisi maka tidak akan dihitung ke lead time') waybill_id = fields.One2many(comodel_name='airway.bill', inverse_name='do_id', string='Airway Bill') @@ -94,6 +96,8 @@ class StockPicking(models.Model): date_availability = fields.Datetime(string="Date Availability", copy=False, tracking=True) sale_order = fields.Char(string='Matches SO', copy=False) printed_sj = fields.Boolean('Printed Surat Jalan', help='flag which is internal use or not') + printed_sj_retur = fields.Boolean('Printed Surat Jalan Retur', help='flag which is internal use or not') + date_printed_sj_retur = fields.Datetime(string='Status Printed Surat Jalan Retur', copy=False, tracking=True) invoice_status = fields.Selection([ ('upselling', 'Upselling Opportunity'), ('invoiced', 'Fully Invoiced'), @@ -101,9 +105,96 @@ class StockPicking(models.Model): ('no', 'Nothing to Invoice') ], string='Invoice Status', related="sale_id.invoice_status") - @api.constrains('driver_departure_date') - def constrains_driver_departure_date(self): - self.date_doc_kirim = self.driver_departure_date + state_reserve = fields.Selection([ + ('waiting', 'Waiting For Fullfilment'), + ('ready', 'Ready to Ship'), + ('done', 'Done'), + ('cancel', 'Cancelled'), + ], string='Status Reserve', readonly=True, tracking=True, help="The current state of the stock picking.") + + def action_send_to_biteship(self): + url = "https://api.biteship.com/v1/orders" + api_key = "biteship_test.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSW5kb3Rla25payIsInVzZXJJZCI6IjY3MTViYTJkYzVkMjdkMDAxMjRjODk2MiIsImlhdCI6MTcyOTQ5ODAwMX0.L6C73couP4-cgVEfhKI2g7eMCMo3YOFSRZhS-KSuHNA" + + # Mencari data sale.order.line berdasarkan sale_id + products = self.env['sale.order.line'].search([('order_id', '=', self.sale_id.id)]) + + # Fungsi untuk membangun items_data dari order lines + def build_items_data(lines): + return [{ + "name": line.product_id.name, + "description": line.name, + "value": line.price_unit, + "quantity": line.product_uom_qty, + "weight": line.weight + } for line in lines] + + # Items untuk pengiriman standard + items_data_standard = build_items_data(products) + + # Items untuk pengiriman instant, mengambil product_id dari move_line_ids_without_package + items_data_instant = [] + for move_line in self.move_line_ids_without_package: + # Mencari baris di sale.order.line berdasarkan product_id dari move_line + order_line = self.env['sale.order.line'].search([ + ('order_id', '=', self.sale_id.id), + ('product_id', '=', move_line.product_id.id) + ], limit=1) + + if order_line: + items_data_instant.append({ + "name": order_line.product_id.name, + "description": order_line.name, + "value": order_line.price_unit, + "quantity": move_line.qty_done, # Menggunakan qty_done dari move_line + "weight": order_line.weight + }) + + payload = { + "shipper_contact_name": self.carrier_id.pic_name or '', + "shipper_contact_phone": self.carrier_id.pic_phone or '', + "shipper_organization": self.carrier_id.name, + "origin_contact_name": "PT. Indoteknik Dotcom Gemilang", + "origin_contact_phone": "081717181922", + "origin_address": "Jl. Bandengan Utara Komp A & BRT. Penjaringan, Kec. Penjaringan, Jakarta (BELAKANG INDOMARET) KOTA JAKARTA UTARA PENJARINGAN", + "origin_postal_code": 14440, + "destination_contact_name": self.real_shipping_id.name, + "destination_contact_phone": self.real_shipping_id.phone or self.real_shipping_id.mobile, + "destination_address": self.real_shipping_id.street, + "destination_postal_code": self.real_shipping_id.zip, + "courier_type": "reg", + "courier_company": self.carrier_id.name.lower(), + "delivery_type": "now", + "destination_postal_code": self.real_shipping_id.zip, + "items": items_data_standard + } + + # Cek jika pengiriman instant atau same_day + if "instant" in self.sale_id.delivery_service_type or "same_day" in self.sale_id.delivery_service_type: + payload.update({ + "origin_note": "BELAKANG INDOMARET", + "courier_company": self.carrier_id.name.lower(), + "courier_type": self.sale_id.delivery_service_type, + "delivery_type": "now", + "items": items_data_instant # Gunakan items untuk instant + }) + + headers = { + "Authorization": f"Bearer {api_key}", + "Content-Type": "application/json" + } + + # Kirim request ke Biteship + response = requests.post(url, headers=headers, json=payload) + + if response.status_code == 201: + return response.json() + else: + raise UserError(f"Error saat mengirim ke Biteship: {response.content}") + + # @api.constrains('driver_departure_date') + # def constrains_driver_departure_date(self): + # self.date_doc_kirim = self.driver_departure_date @api.constrains('arrival_time') def constrains_arrival_time(self): @@ -134,9 +225,44 @@ class StockPicking(models.Model): res = super(StockPicking, self).do_unreserve() current_time = datetime.datetime.utcnow() self.date_unreserve = current_time + # self.check_state_reserve() return res + # def check_state_reserve(self): + # do = self.search([ + # ('state', 'not in', ['cancel', 'draft', 'done']), + # ('picking_type_code', '=', 'outgoing') + # ]) + + # for rec in do: + # rec.state_reserve = 'ready' + # rec.date_reserved = datetime.datetime.utcnow() + + # for line in rec.move_ids_without_package: + # if line.product_uom_qty > line.reserved_availability: + # rec.state_reserve = 'waiting' + # rec.date_reserved = '' + # break + + def check_state_reserve(self): + pickings = self.search([ + ('state', 'not in', ['cancel', 'draft', 'done']), + ('picking_type_code', '=', 'outgoing') + ]) + + for picking in pickings: + fullfillments = self.env['sales.order.fullfillment'].search([ + ('sales_order_id', '=', picking.sale_id.id) + ]) + + picking.state_reserve = 'ready' + picking.date_reserved = picking.date_reserved or datetime.datetime.utcnow() + + if any(rec.reserved_from not in ['Inventory On Hand', 'Reserved from stock', 'Free Stock'] for rec in fullfillments): + picking.state_reserve = 'waiting' + picking.date_reserved = '' + def _create_approval_notification(self, approval_role): title = 'Warning' message = f'Butuh approval sales untuk unreserved' @@ -275,6 +401,7 @@ class StockPicking(models.Model): current_time = datetime.datetime.utcnow() self.real_shipping_id = self.sale_id.real_shipping_id self.date_availability = current_time + # self.check_state_reserve() return res def ask_approval(self): @@ -417,10 +544,11 @@ class StockPicking(models.Model): self.date_reserved = current_time self.validation_minus_onhand_quantity() - + self.responsible = self.env.user.id res = super(StockPicking, self).button_validate() self.calculate_line_no() self.date_done = datetime.datetime.utcnow() + self.state_reserve = 'done' return res @api.model diff --git a/indoteknik_custom/models/user_company_request.py b/indoteknik_custom/models/user_company_request.py index 6d809385..86e66934 100644 --- a/indoteknik_custom/models/user_company_request.py +++ b/indoteknik_custom/models/user_company_request.py @@ -23,24 +23,25 @@ class UserCompanyRequest(models.Model): else: record.similar_company_ids = [(6, 0, [])] - def get_similar_companies(self, user_input): - query = """ - SELECT id - FROM res_partner - WHERE levenshtein(name::text, %s) < 3 - ORDER BY levenshtein(name::text, %s) ASC - """ - self.env.cr.execute(query, (user_input, user_input)) - return [row[0] for row in self.env.cr.fetchall()] + # def get_similar_companies(self, user_input): + # query = """ + # SELECT id + # FROM res_partner + # WHERE levenshtein(name::text, %s) < 3 + # ORDER BY levenshtein(name::text, %s) ASC + # """ + # self.env.cr.execute(query, (user_input, user_input)) + # return [row[0] for row in self.env.cr.fetchall()] def get_similar_companies(self, user_input): query = """ SELECT id FROM res_partner - WHERE name ILIKE %s OR levenshtein(name::text, %s) < 3 + WHERE (name ILIKE %s OR levenshtein(name::text, %s) < 3) + AND active = TRUE AND is_company = TRUE ORDER BY levenshtein(name::text, %s) ASC """ - # Using '%' to match the partial company name + # Menggunakan '%' untuk mencocokkan nama perusahaan sebagian self.env.cr.execute(query, ('%' + user_input + '%', user_input, user_input)) company_ids = [row[0] for row in self.env.cr.fetchall()] return company_ids diff --git a/indoteknik_custom/models/vendor_approval.py b/indoteknik_custom/models/vendor_approval.py index e540b8fc..b0d58b85 100644 --- a/indoteknik_custom/models/vendor_approval.py +++ b/indoteknik_custom/models/vendor_approval.py @@ -29,7 +29,7 @@ class VendorApproval(models.Model): raise UserError('Hanya Merchandiser yang bisa approve') self.state = 'done' - self.order_id.update({'vendor_approval': True}) + self.order_id.vendor_approval = True self.order_id.action_confirm() message = "Vendor Approval approved by %s" % (self.env.user.name) self.order_id.message_post(body=message) diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index d9fb7247..eed5413e 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -192,27 +192,6 @@ class WatiHistory(models.Model): is_get_attribute = fields.Boolean(string='Get Attribute', default=False) def _get_attribute_wati(self): - # url = 'https://live-server-2106.wati.io/api/v1/getContacts' - - # cookies = { - # 'affinity': '1701232090.884.1520.321410|ff187ffce9bc0bae13542bb446e41008', - # } - - # headers = { - # 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3MGM5ZmJhNy00MWRlLTRkMWEtYjY2NS1hM2Q5ODc2ZjhlZWIiLCJ1bmlxdWVfbmFtZSI6InR5YXNAaW5kb3Rla25pay5jb20iLCJuYW1laWQiOiJ0eWFzQGluZG90ZWtuaWsuY29tIiwiZW1haWwiOiJ0eWFzQGluZG90ZWtuaWsuY29tIiwiYXV0aF90aW1lIjoiMTEvMjkvMjAyMyAwNDoxNzo0NyIsImRiX25hbWUiOiIyMTA2IiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQURNSU5JU1RSQVRPUiIsImV4cCI6MjUzNDAyMzAwODAwLCJpc3MiOiJDbGFyZV9BSSIsImF1ZCI6IkNsYXJlX0FJIn0.--KHv4GCOG2MM3lNW9Nm-0-d8OAVpn5kbcSX4JKqATQ', - # # 'Cookie': 'affinity=1701232090.884.1520.321410|ff187ffce9bc0bae13542bb446e41008', - # } - - # files = { - # 'pageSize': (None, '1'), - # 'pageNumber': (None, '1'), - # 'name': (None, ''), - # 'attribute': (None, '[{name: "phone", operator: "contain", value: "6285751430014"}]'), - # 'createdDate': (None, ''), - # } - - # response = requests.get(url, cookies=cookies, headers=headers, files=files) - # print(response.json()) domain = [ '&', ('is_get_attribute', '=', False), @@ -226,29 +205,36 @@ class WatiHistory(models.Model): for wati_history in wati_histories: count += 1 _logger.info('[Parse Notification] Process: %s/%s' % (str(count), str(limit))) + wati_api = self.env['wati.api'] + + # Perbaikan pada params 'attribute' untuk menghindari masalah "type object is not subscriptable" params = { - 'pageSize':1, - 'pageNumber':1, - 'attribute':[{'name': "phone", 'operator': "contain", 'value': wati_history.wa_id}], + 'pageSize': 1, + 'pageNumber': 1, + 'attribute': json.dumps([{'name': "phone", 'operator': "contain", 'value': wati_history.wa_id}]), } + wati_contacts = wati_api.http_get('/api/v1/getContacts', params) - if wati_contacts['result'] != 'success': + + if wati_contacts.get('result') != 'success': return - json_dump = json.dumps(wati_contacts, indent=4, sort_keys=True) - contact_list = json.loads(json_dump)['contact_list'] + + contact_list = wati_contacts.get('contact_list', []) + perusahaan = email = '' for data in contact_list: - custom_params = data['customParams'] + custom_params = data.get('customParams', []) for custom_param in custom_params: - name = custom_param['name'] - value = custom_param['value'] + name = custom_param.get('name') + value = custom_param.get('value') if name == 'perusahaan': perusahaan = value elif name == 'email': email = value - # end for 2 - # end for 1 + # End inner loop + + # Update wati_history fields wati_history.perusahaan = perusahaan wati_history.email = email wati_history.is_get_attribute = True diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 9dadc40b..494f32f3 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -95,22 +95,31 @@ class WebsiteUserCart(models.Model): def get_product_by_user(self, user_id, selected=False, source=False): user_id = int(user_id) - + if source == 'buy': source = ['buy'] else: source = ['add_to_cart', 'buy'] parameters = [ - ('user_id', '=', user_id), + ('user_id', '=', user_id), ('source', 'in', source) ] + carts = self.search(parameters) + + for cart in carts: + if cart.product_id: + price = cart.product_id._v2_get_website_price_include_tax() + if not cart.product_id.active or price < 1: + cart.is_selected = False if selected: parameters.append(('is_selected', '=', True)) - carts = self.search(parameters) - products = carts.get_products() + products_active = self.search(parameters) + + products = products_active.get_products() + return products def get_user_checkout(self, user_id, voucher=False, voucher_shipping=False, source=False): diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 408aae55..553047e6 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -141,3 +141,5 @@ access_approval_unreserve_line,access.approval.unreserve.line,model_approval_unr access_vendor_approval,access.vendor.approval,model_vendor_approval,,1,1,1,1 access_vendor_approval_line,access.vendor.approval.line,model_vendor_approval_line,,1,1,1,1 access_vit_kota,access.vit.kota,model_vit_kota,,1,1,1,1 +access_v_brand_product_category,access.v.brand.product.category,model_v_brand_product_category,,1,1,1,1 +access_web_find_page,access.web.find.page,model_web_find_page,,1,1,1,1 diff --git a/indoteknik_custom/views/account_move_views.xml b/indoteknik_custom/views/account_move_views.xml index 4acafb14..da25636e 100644 --- a/indoteknik_custom/views/account_move_views.xml +++ b/indoteknik_custom/views/account_move_views.xml @@ -12,6 +12,10 @@ <field name="description"/> <field name="approval_status"/> <field name="is_approve"/> + <field name="approve_by" optional="hide"/> + <field name="date_approve" optional="hide"/> + <field name="create_uid" optional="hide"/> + <field name="create_date" optional="hide"/> </tree> </field> </record> @@ -58,12 +62,14 @@ <group> <field name="partner_id" readonly="1"/> <field name="day_extension" attrs="{'readonly': [('is_approve', '=', True)]}"/> + <field name="order_id" readonly="1"/> </group> <group> <field name="is_approve" readonly="1"/> - <field name="order_id" readonly="1"/> <field name="counter" readonly="1"/> <field name="approval_status" readonly="1"/> + <field name="approve_by" readonly="1"/> + <field name="date_approve" readonly="1"/> </group> </group> <group> diff --git a/indoteknik_custom/views/dunning_run.xml b/indoteknik_custom/views/dunning_run.xml index 522be8c9..2117a7bb 100644 --- a/indoteknik_custom/views/dunning_run.xml +++ b/indoteknik_custom/views/dunning_run.xml @@ -14,6 +14,7 @@ <field name="date_terima_tukar_faktur"/> <field name="shipper_faktur_id"/> <field name="grand_total"/> + <field name="create_uid" optional="hide"/> </tree> </field> </record> diff --git a/indoteknik_custom/views/find_page.xml b/indoteknik_custom/views/find_page.xml new file mode 100644 index 00000000..c752aa98 --- /dev/null +++ b/indoteknik_custom/views/find_page.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <record id="web_find_page_tree" model="ir.ui.view"> + <field name="name">web.find.page.tree</field> + <field name="model">web.find.page</field> + <field name="arch" type="xml"> + <tree> + <field name="category_id"/> + <field name="brand_id"/> + <field name="url"/> + <field name="create_uid"/> + <field name="write_uid"/> + </tree> + </field> + </record> + + <record id="web_find_page_form" model="ir.ui.view"> + <field name="name">web.find.page.form</field> + <field name="model">web.find.page</field> + <field name="arch" type="xml"> + <form> + <sheet string="Web Find Page"> + <div class="oe_button_box" name="button_box"/> + <group> + <group> + <field name="category_id"/> + <field name="brand_id"/> + <field name="url"/> + </group> + <group> + <field name="create_uid"/> + <field name="write_uid"/> + </group> + </group> + </sheet> + <div class="oe_chatter"> + <field name="message_follower_ids" widget="mail_followers"/> + <field name="message_ids" widget="mail_thread"/> + </div> + </form> + </field> + </record> + + <record id="view_web_find_page_filter" model="ir.ui.view"> + <field name="name">web.find.page.list.select</field> + <field name="model">web.find.page</field> + <field name="priority" eval="15"/> + <field name="arch" type="xml"> + <search string="Search Web Find Page"> + <field name="category_id"/> + <field name="brand_id"/> + <field name="url"/> + </search> + </field> + </record> + + <record id="web_find_page_action" model="ir.actions.act_window"> + <field name="name">Web Find Page</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">web.find.page</field> + <field name="search_view_id" ref="view_web_find_page_filter"/> + <field name="view_mode">tree,form</field> + </record> + + <menuitem id="menu_web_find_page" + name="Web Find Page" + action="web_find_page_action" + parent="website_sale.menu_orders" + sequence="8"/> +</odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 3e609f15..0e6b6792 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -27,7 +27,11 @@ <button name="delete_line" type="object" string="Delete " states="draft"/> </button> <button name="button_unlock" position="after"> - <button name="create_bill_dp" string="Create Bill DP" type="object" class="oe_highlight" attrs="{'invisible': [('state', 'not in', ('purchase', 'done'))]}"/> + <button name="create_bill_dp" string="Create Bill DP" type="object" class="oe_highlight" attrs="{'invisible': [('state', 'not in', ('purchase', 'done')), ('bills_pelunasan_id', '!=', False)]}"/> + </button> + <button name="button_unlock" position="after"> + <button name="create_bill_pelunasan" string="Create Bill Pelunasan" type="object" class="oe_highlight" attrs="{'invisible': [('state', 'not in', ('purchase', 'done')), ('bills_pelunasan_id', '!=', False)]}"/> + </button> <field name="date_order" position="before"> <field name="sale_order_id" attrs="{'readonly': [('state', 'not in', ['draft'])]}"/> @@ -100,6 +104,7 @@ <field name="approval_edit_line"/> <field name="logbook_bill_id"/> <field name="bills_dp_id" readonly="1"/> + <field name="bills_pelunasan_id" readonly="1"/> </field> <field name="order_line" position="attributes"> @@ -207,7 +212,6 @@ <field name="code">model.procure_calculation()</field> <field name="state">code</field> <field name="priority">75</field> - <field name="active">True</field> </record> </data> <data> diff --git a/indoteknik_custom/views/requisition.xml b/indoteknik_custom/views/requisition.xml index 652d03d0..a866690d 100644 --- a/indoteknik_custom/views/requisition.xml +++ b/indoteknik_custom/views/requisition.xml @@ -50,6 +50,13 @@ <field name="model">requisition</field> <field name="arch" type="xml"> <form> + <header> + <button name="button_approve" + string="Approve" + type="object" + class="mr-2 oe_highlight" + /> + </header> <sheet string="Requisition"> <div class="oe_button_box" name="button_box"/> <group> @@ -78,6 +85,7 @@ <field name="partner_id" required="1" /> <field name="qty_purchase" required="1" /> <field name="price_unit" required="1" /> + <field name="taxes_id" readonly="1" /> <field name="subtotal" readonly="1" /> <field name="brand_id" /> </tree> diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 895b242c..98001589 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -73,6 +73,7 @@ <field name="margin_after_delivery_purchase"/> <field name="percent_margin_after_delivery_purchase"/> <field name="total_weight"/> + <field name="pareto_status"/> </field> <field name="analytic_account_id" position="after"> <field name="customer_type" required="1"/> @@ -140,7 +141,6 @@ <field name="weight" optional="hide"/> <field name="amount_voucher_disc" string="Voucher" readonly="1" optional="hide"/> <field name="order_promotion_id" string="Promotion" readonly="1" optional="hide"/> - <field name="md_vendor_id" string="MD Vendor" readonly="1" optional="hide"/> </xpath> <xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='product_id']" position="before"> <field name="line_no" readonly="1" optional="hide"/> @@ -245,6 +245,7 @@ <field name="client_order_ref"/> <field name="payment_type" optional="hide"/> <field name="payment_status" optional="hide"/> + <field name="pareto_status" optional="hide"/> </field> </field> </record> @@ -263,6 +264,7 @@ <field name="date_driver_arrival"/> <field name="payment_type" optional="hide"/> <field name="payment_status" optional="hide"/> + <field name="pareto_status" optional="hide"/> </field> </field> </record> diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml index 899d29eb..c230bc7b 100644 --- a/indoteknik_custom/views/stock_picking.xml +++ b/indoteknik_custom/views/stock_picking.xml @@ -16,6 +16,8 @@ <field name="driver_arrival_date" optional="hide"/> <field name="note_logistic" optional="hide"/> <field name="note" optional="hide"/> + <field name="date_reserved" optional="hide"/> + <field name="state_reserve" optional="hide"/> </field> <field name="partner_id" position="after"> <field name="purchase_representative_id"/> @@ -50,6 +52,10 @@ type="object" attrs="{'invisible': ['|', ('state', '!=', 'done'), ('name', 'ilike', 'out')]}" /> + <button name="action_send_to_biteship" + string="Biteship" + type="object" + /> </button> <field name="backorder_id" position="after"> <field name="summary_qty_detail"/> @@ -91,6 +97,8 @@ <field name="status_printed"/> <field name="printed_sj"/> <field name="date_printed_sj"/> + <field name="printed_sj_retur"/> + <field name="date_printed_sj_retur"/> <field name="date_printed_list"/> <field name="is_internal_use" string="Internal Use" @@ -122,13 +130,17 @@ <group> <group> <field name="note_logistic"/> + <field name="responsible" /> + <field name="carrier_id"/> + <field name="picking_code" attrs="{'invisible': [['picking_code', '=', False]]}"/> + <field name="picking_code" string="Picking code (akan digenerate ketika sudah di-validate)" attrs="{'invisible': [['picking_code', '!=', False]]}"/> <field name="driver_departure_date" attrs="{'readonly':[('invoice_status', '=', 'invoiced')]}"/> <field name="driver_arrival_date"/> <field name="delivery_tracking_no"/> <field name="driver_id"/> - <field name="carrier_id"/> - <field name="picking_code" attrs="{'invisible': [['picking_code', '=', False]]}"/> - <field name="picking_code" string="Picking code (akan digenerate ketika sudah di-validate)" attrs="{'invisible': [['picking_code', '!=', False]]}"/> + <field name='sj_return_date'/> + <field name="sj_documentation" widget="image" /> + <field name="paket_documentation" widget="image" /> </group> </group> </page> |
