diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2024-11-06 16:47:04 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2024-11-06 16:47:04 +0700 |
| commit | 659baaa6753ec030dc4d5d46564109c25caf865e (patch) | |
| tree | dbd0b32dc765b6f101a288b86c8cb0230cef6382 | |
| parent | 3b1c519848d69709aa64ff6078c7d2d45dc356b1 (diff) | |
| parent | 295088070b43c409c2114a0a98d898ff3ff4ae7b (diff) | |
Merge branch 'production' of https://bitbucket.org/altafixco/indoteknik-addons into production
| -rw-r--r-- | indoteknik_api/controllers/api_v1/cart.py | 21 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/partner.py | 6 | ||||
| -rw-r--r-- | indoteknik_custom/models/approval_unreserve.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/delivery_order.py | 8 | ||||
| -rw-r--r-- | indoteknik_custom/models/logbook_sj.py | 6 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 29 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 21 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_product.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_template.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/wati.py | 50 | ||||
| -rw-r--r-- | indoteknik_custom/models/website_user_cart.py | 24 | ||||
| -rwxr-xr-x | indoteknik_custom/views/purchase_order.xml | 1 |
12 files changed, 127 insertions, 43 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_custom/models/approval_unreserve.py b/indoteknik_custom/models/approval_unreserve.py index 07ddda1f..ba8b8da7 100644 --- a/indoteknik_custom/models/approval_unreserve.py +++ b/indoteknik_custom/models/approval_unreserve.py @@ -74,7 +74,7 @@ class ApprovalUnreserve(models.Model): 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': diff --git a/indoteknik_custom/models/delivery_order.py b/indoteknik_custom/models/delivery_order.py index be5fd2e0..2ed49a54 100644 --- a/indoteknik_custom/models/delivery_order.py +++ b/indoteknik_custom/models/delivery_order.py @@ -37,7 +37,7 @@ class DeliveryOrder(models.TransientModel): if delivery_type == 'departure': picking.driver_departure_date = current_time elif delivery_type == 'arrival': - picking.driver_arrival_date = current_time + picking.sj_return_date = datetime.utcnow() sale_order = False if picking.origin: @@ -103,14 +103,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/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/purchase_order.py b/indoteknik_custom/models/purchase_order.py index c24bdbb3..6fc0c497 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -121,11 +121,23 @@ class PurchaseOrder(models.Model): 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], @@ -139,9 +151,11 @@ class PurchaseOrder(models.Model): 'name': self.name + ": " + line.product_id.display_name, 'account_id': 439, # Uang Muka persediaan barang dagang 'quantity': line.product_qty, - 'price_unit': line.price_unit, + # '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) @@ -716,7 +730,20 @@ class PurchaseOrder(models.Model): elif self.total_percent_margin == self.total_so_percent_margin and self.sale_order_id: 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.sale_order_id: + reason += 'not link with sales, ' + # 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 Return (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/sale_order.py b/indoteknik_custom/models/sale_order.py index 1ad08154..8e170b1c 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -768,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: 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/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 26e217cb..fbcb0aa4 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -108,8 +108,30 @@ class WebsiteUserCart(models.Model): parameters.append(('is_selected', '=', True)) carts = self.search(parameters) + 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) + data = { + 'product_total': self.search_count(parameters), + 'products': products_active, + 'products_inactive': products_inactive + } products = carts.get_products() - return products + return products_active def get_user_checkout(self, user_id, voucher=False, voucher_shipping=False, source=False): products = self.get_product_by_user(user_id=user_id, selected=True, source=source) diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 06c76a82..0e6b6792 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -212,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> |
