From a2d93b35cc849d742e851f5d876557ac18c1a9e1 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 2 Oct 2024 10:41:13 +0700 Subject: cr function get id partner --- indoteknik_custom/models/sale_order.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 8f48e898..8c506c47 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -140,18 +140,27 @@ class SaleOrder(models.Model): for line in self.order_line: if line.weight: total_weight += line.weight + line.product_id.weight = line.weight else: missing_weight_products.append(line.product_id.name) + if missing_weight_products: + product_names = ', '.join(missing_weight_products) + self.message_post(body=f"Produk berikut tidak memiliki berat: {product_names}") + if total_weight == 0: raise UserError("Tidak dapat mengestimasi ongkir tanpa berat yang valid.") # Mendapatkan city_id berdasarkan nama kota origin_city_name = self.warehouse_id.partner_id.kota_id.name destination_city_name = self.real_shipping_id.kota_id.name - - origin_city_id = self._get_city_id_by_name(origin_city_name) - destination_city_id = self._get_city_id_by_name(destination_city_name) + origin_subdistrict_name = self.warehouse_id.partner_id.kecamatan_id.name + destination_subdistrict_name = self.real_shipping_id.kecamatan_id.name + + origin_id_city = self._get_city_id_by_name(origin_city_name) + destination_id_city = self._get_city_id_by_name(destination_city_name) + origin_city_id = self._get_subdistrict_id_by_name(origin_id_city, origin_subdistrict_name) + destination_city_id = self._get_subdistrict_id_by_name(destination_id_city, destination_subdistrict_name) if not origin_city_id or not destination_city_id: raise UserError("Gagal mendapatkan ID kota asal atau tujuan.") @@ -160,7 +169,8 @@ class SaleOrder(models.Model): if result: estimated_cost = result['rajaongkir']['results'][0]['costs'][0]['cost'][0]['value'] self.delivery_amt = estimated_cost - self.message_post(body=f"Estimasi Ongkos Kirim: {estimated_cost}") + self.message_post(body=f"Estimasi Ongkos Kirim: {self.delivery_amt}") + else: raise UserError("Gagal mendapatkan estimasi ongkir.") @@ -173,9 +183,9 @@ class SaleOrder(models.Model): data = { 'origin': int(origin_city_id), - 'originType': 'city', + 'originType': 'subdistrict', 'destination': int(destination_city_id), - 'destinationType': 'city', + 'destinationType': 'subdistrict', 'weight': int(total_weight * 1000), 'courier': courier, } @@ -186,16 +196,13 @@ class SaleOrder(models.Model): return None def _normalize_city_name(self, city_name): - # Ubah nama kota menjadi huruf kecil city_name = city_name.lower() - # Hilangkan prefiks "kabupaten" atau "kota" jika ada if city_name.startswith('kabupaten'): city_name = city_name.replace('kabupaten', '').strip() elif city_name.startswith('kota'): city_name = city_name.replace('kota', '').strip() - # Hilangkan spasi yang berlebihan city_name = " ".join(city_name.split()) return city_name @@ -206,7 +213,6 @@ class SaleOrder(models.Model): 'key': '7ac9883688da043b50cc32f0e3070bb6', } - # Normalisasi nama kota sebelum melakukan pencarian normalized_city_name = self._normalize_city_name(city_name) response = requests.get(url, headers=headers) -- cgit v1.2.3 From 27a603a8bc4750dcacd295e07144c5ce2621783c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 2 Oct 2024 15:10:46 +0700 Subject: cr estimated shipping price + cr user company request --- indoteknik_custom/models/sale_order.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 8c506c47..2b20a533 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -145,8 +145,9 @@ class SaleOrder(models.Model): missing_weight_products.append(line.product_id.name) if missing_weight_products: - product_names = ', '.join(missing_weight_products) - self.message_post(body=f"Produk berikut tidak memiliki berat: {product_names}") + product_names = '\n'.join(missing_weight_products) + self.message_post(body=f"Produk berikut tidak memiliki berat: \n{product_names}") + if total_weight == 0: raise UserError("Tidak dapat mengestimasi ongkir tanpa berat yang valid.") -- cgit v1.2.3 From 8b63d79efe0137ce6af535847f33868e73ce8d3c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 2 Oct 2024 15:31:02 +0700 Subject: add validation data realshippingaddress --- indoteknik_custom/models/sale_order.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 2b20a533..f8127d8c 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -419,6 +419,22 @@ class SaleOrder(models.Model): for line in order.order_line: total += line.vendor_subtotal order.purchase_total = total + + def check_data_real_delivery_address(self): + real_delivery_address = self.real_shipping_id + + if not real_delivery_address.state_id: + raise UserError('State Real Delivery Address harus diisi') + if not real_delivery_address.zip: + raise UserError('Zip code Real Delivery Address harus diisi') + if not real_delivery_address.mobile: + raise UserError('Mobile Real Delivery Address harus diisi') + if not real_delivery_address.phone: + raise UserError('Phone Real Delivery Address harus diisi') + if not real_delivery_address.kecamatan_id: + raise UserError('Kecamatan Real Delivery Address harus diisi') + if not real_delivery_address.kelurahan_id: + raise UserError('Kelurahan Real Delivery Address harus diisi') def generate_payment_link_midtrans_sales_order(self): # midtrans_url = 'https://app.sandbox.midtrans.com/snap/v1/transactions' # dev - sandbox @@ -565,8 +581,6 @@ class SaleOrder(models.Model): raise UserError('Phone Real Delivery Address harus diisi') if not real_delivery_address.kecamatan_id: raise UserError('Kecamatan Real Delivery Address harus diisi') - if not real_delivery_address.kelurahan_id: - raise UserError('Kelurahan Real Delivery Address harus diisi') @api.onchange('partner_id') def onchange_partner_contact(self): @@ -791,6 +805,7 @@ class SaleOrder(models.Model): def action_confirm(self): for order in self: + order.check_data_real_delivery_address() order.sale_order_check_approve() order._validate_order() order.order_line.validate_line() -- cgit v1.2.3 From 4a69c71eab2d4ea3504a0cf6e3a9ca241be48594 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 3 Oct 2024 10:12:24 +0700 Subject: push --- indoteknik_custom/models/sale_order.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index f8127d8c..538e0209 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -145,9 +145,8 @@ class SaleOrder(models.Model): missing_weight_products.append(line.product_id.name) if missing_weight_products: - product_names = '\n'.join(missing_weight_products) - self.message_post(body=f"Produk berikut tidak memiliki berat: \n{product_names}") - + product_names = '
'.join(missing_weight_products) + self.message_post(body=f"Produk berikut tidak memiliki berat:
{product_names}") if total_weight == 0: raise UserError("Tidak dapat mengestimasi ongkir tanpa berat yang valid.") @@ -802,9 +801,36 @@ class SaleOrder(models.Model): 'body_html': email_body, 'email_to': salesperson_email, }).send() + + def validate_different_vendor(self): + different_vendor = self.order_line.filtered(lambda l: l.vendor_id.id != l.vendor_md_id.id) + if different_vendor: + vendor_approval = self.env['vendor.approval'].create({ + 'order_id': self.id, + 'state': 'draft', + }) + for line in self.line: + self.env['vendor.approval.line'].create({ + 'vendor_approval_id': vendor_approval.id, + 'product_id': line.product_id.id, + 'product_uom_qty': line.product_uom_qty, + 'vendor_id': line.vendor_id.id, + 'vendor_md_id': line.vendor_md_id.id, + 'purchase_price': line.purchase_price, + 'purchase_price_md': line.purchase_price_md, + }) + + return True + else: + return False + + def action_confirm(self): for order in self: + if order.validate_partner_invoice_due(): + return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') + order.check_data_real_delivery_address() order.sale_order_check_approve() order._validate_order() -- cgit v1.2.3 From 7059f095dd09649f7c12f74ff29200f644bbc854 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 3 Oct 2024 11:55:16 +0700 Subject: push --- indoteknik_custom/models/sale_order.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 538e0209..a6ea6c81 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -78,6 +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) customer_type = fields.Selection([ ('pkp', 'PKP'), ('nonpkp', 'Non PKP') @@ -104,6 +105,7 @@ class SaleOrder(models.Model): ('cust_procurement', 'Customer Procurement') ], string='Web Approval', copy=False) compute_fullfillment = fields.Boolean(string='Compute Fullfillment', compute="_compute_fullfillment") + vendor_approval = fields.Boolean(string='Vendor Approval') note_ekspedisi = fields.Char(string="Note Ekspedisi") date_kirim_ril = fields.Datetime(string='Tanggal Kirim SJ', compute='_compute_date_kirim', copy=False) date_status_done = fields.Datetime(string='Date Done DO', compute='_compute_date_kirim', copy=False) @@ -703,6 +705,8 @@ class SaleOrder(models.Model): self._validate_order() for order in self: order.order_line.validate_line() + if order.validate_different_vendor() and not self.vendor_approval: + return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') partner = order.partner_id.parent_id or order.partner_id if not partner.property_payment_term_id: @@ -803,12 +807,14 @@ class SaleOrder(models.Model): }).send() def validate_different_vendor(self): - different_vendor = self.order_line.filtered(lambda l: l.vendor_id.id != l.vendor_md_id.id) + 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, 'state': 'draft', }) + + self.vendor_approval_id = vendor_approval.id for line in self.line: self.env['vendor.approval.line'].create({ 'vendor_approval_id': vendor_approval.id, @@ -823,12 +829,10 @@ class SaleOrder(models.Model): return True else: return False - - def action_confirm(self): for order in self: - if order.validate_partner_invoice_due(): + if order.validate_different_vendor() and not self.vendor_approval: return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') order.check_data_real_delivery_address() -- cgit v1.2.3 From 48c220d1c38f435962b8b630c5209ba781ca30df Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 4 Oct 2024 14:23:59 +0700 Subject: push --- indoteknik_custom/models/sale_order.py | 71 +++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 19 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index a6ea6c81..0f22a7d4 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -135,6 +135,12 @@ class SaleOrder(models.Model): 'account.payment.term', string='Payment Terms', check_company=True, # Unrequired company domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", tracking=True) + total_weight = fields.Float(string='Total Weight', compute='_compute_total_weight') + + def _compute_total_weight(self): + for order in self: + order.total_weight = sum(line.weight for line in order.order_line) + def action_estimate_shipping(self): total_weight = 0 missing_weight_products = [] @@ -155,38 +161,45 @@ class SaleOrder(models.Model): # Mendapatkan city_id berdasarkan nama kota origin_city_name = self.warehouse_id.partner_id.kota_id.name - destination_city_name = self.real_shipping_id.kota_id.name - origin_subdistrict_name = self.warehouse_id.partner_id.kecamatan_id.name - destination_subdistrict_name = self.real_shipping_id.kecamatan_id.name + destination_subsdistrict_id = self.real_shipping_id.kecamatan_id.rajaongkir_id - origin_id_city = self._get_city_id_by_name(origin_city_name) - destination_id_city = self._get_city_id_by_name(destination_city_name) - origin_city_id = self._get_subdistrict_id_by_name(origin_id_city, origin_subdistrict_name) - destination_city_id = self._get_subdistrict_id_by_name(destination_id_city, destination_subdistrict_name) - - if not origin_city_id or not destination_city_id: + if not destination_subsdistrict_id: raise UserError("Gagal mendapatkan ID kota asal atau tujuan.") - result = self._call_rajaongkir_api(total_weight, origin_city_id, destination_city_id) + result = self._call_rajaongkir_api(total_weight, destination_subsdistrict_id) if result: estimated_cost = result['rajaongkir']['results'][0]['costs'][0]['cost'][0]['value'] self.delivery_amt = estimated_cost - self.message_post(body=f"Estimasi Ongkos Kirim: {self.delivery_amt}") + shipping_info = [] + for courier in result['rajaongkir']['results']: + for cost_detail in courier['costs']: + service = cost_detail['service'] + description = cost_detail['description'] + etd = cost_detail['cost'][0]['etd'] + value = cost_detail['cost'][0]['value'] + shipping_info.append(f"Service: {service}, Description: {description}, ETD: {etd} hari, Cost: Rp {value}") + + log_message = "
".join(shipping_info) + + description_ongkir = result['rajaongkir']['results'][0]['costs'][0]['description'] + etd_ongkir = result['rajaongkir']['results'][0]['costs'][0]['cost'][0]['etd'] + service_ongkir = result['rajaongkir']['results'][0]['costs'][0]['service'] + self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Service: {service_ongkir}
Description: {description_ongkir}
ETD: {etd_ongkir}
Detail Lain:
{log_message}") else: raise UserError("Gagal mendapatkan estimasi ongkir.") - def _call_rajaongkir_api(self, total_weight, origin_city_id, destination_city_id): + def _call_rajaongkir_api(self, total_weight, destination_subsdistrict_id): url = 'https://pro.rajaongkir.com/api/cost' headers = { - 'key': '7ac9883688da043b50cc32f0e3070bb6', + 'key': '9b1310f644056d84d60b0af6bb21611a', } courier = self.carrier_id.name.lower() data = { - 'origin': int(origin_city_id), + 'origin': 2127, 'originType': 'subdistrict', - 'destination': int(destination_city_id), + 'destination': int(destination_subsdistrict_id), 'destinationType': 'subdistrict', 'weight': int(total_weight * 1000), 'courier': courier, @@ -212,7 +225,7 @@ class SaleOrder(models.Model): def _get_city_id_by_name(self, city_name): url = 'https://pro.rajaongkir.com/api/city' headers = { - 'key': '7ac9883688da043b50cc32f0e3070bb6', + 'key': '9b1310f644056d84d60b0af6bb21611a', } normalized_city_name = self._normalize_city_name(city_name) @@ -228,14 +241,17 @@ class SaleOrder(models.Model): def _get_subdistrict_id_by_name(self, city_id, subdistrict_name): url = f'https://pro.rajaongkir.com/api/subdistrict?city={city_id}' headers = { - 'key': '7ac9883688da043b50cc32f0e3070bb6', + 'key': '9b1310f644056d84d60b0af6bb21611a', } response = requests.get(url, headers=headers) if response.status_code == 200: subdistrict_data = response.json() for subdistrict in subdistrict_data['rajaongkir']['results']: - if subdistrict['subdistrict_name'].lower() == subdistrict_name.lower(): + subsdistrict_1 = subdistrict['subdistrict_name'].lower() + subsdistrict_2 = subdistrict_name.lower() + + if subsdistrict_1 == subsdistrict_2: return subdistrict['subdistrict_id'] return None @@ -808,14 +824,24 @@ class SaleOrder(models.Model): 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 different_vendor: vendor_approval = self.env['vendor.approval'].create({ 'order_id': self.id, + 'create_date_so': self.create_date, + 'partner_id': self.partner_id.id, 'state': 'draft', }) self.vendor_approval_id = vendor_approval.id - for line in self.line: + + for line in different_vendor: self.env['vendor.approval.line'].create({ 'vendor_approval_id': vendor_approval.id, 'product_id': line.product_id.id, @@ -824,11 +850,18 @@ class SaleOrder(models.Model): 'vendor_md_id': line.vendor_md_id.id, 'purchase_price': line.purchase_price, 'purchase_price_md': line.purchase_price_md, + 'sales_price': line.price_unit, + 'margin_before': line.margin_md, + 'margin_after': line.item_percent_margin, + 'purchase_tax_id': line.purchase_tax_id.id, + 'sales_tax_id': line.tax_id[0].id if line.tax_id else False, + 'percent_margin_difference': (line.price_unit - line.purchase_price_md) / line.purchase_price_md if line.purchase_price_md else False, }) return True else: return False + def action_confirm(self): for order in self: -- cgit v1.2.3 From 04709ff9faa72f0c9d6ca4a51f203859e79596de Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 7 Oct 2024 10:35:40 +0700 Subject: cr vendor approval --- indoteknik_custom/models/sale_order.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 0f22a7d4..f24a4bf3 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -716,13 +716,13 @@ class SaleOrder(models.Model): raise UserError("Salesperson sudah tidak aktif, mohon diisi yang benar pada data SO dan Contact") def sale_order_approve(self): + if self.validate_different_vendor() and not self.vendor_approval and not self.vendor_approval_id: + return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') self.check_due() self._validate_order() for order in self: order.order_line.validate_line() - if order.validate_different_vendor() and not self.vendor_approval: - return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') partner = order.partner_id.parent_id or order.partner_id if not partner.property_payment_term_id: @@ -865,7 +865,7 @@ class SaleOrder(models.Model): def action_confirm(self): for order in self: - if order.validate_different_vendor() and not self.vendor_approval: + if self.validate_different_vendor() and not self.vendor_approval and not self.vendor_approval_id: return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') order.check_data_real_delivery_address() -- cgit v1.2.3 From 6b6a7d9f271106325133f1ec84c66717d2eec711 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 7 Oct 2024 11:12:30 +0700 Subject: cr credit limit validation --- indoteknik_custom/models/sale_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index f24a4bf3..265ffb9e 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -702,7 +702,7 @@ class SaleOrder(models.Model): partner = order.partner_id.parent_id or order.partner_id if not partner.property_payment_term_id: raise UserError("Payment Term pada Master Data Customer harus diisi") - if not partner.active_limit: + if not partner.active_limit and order.payment_term_id.id not in [27, 26]: raise UserError("Credit Limit pada Master Data Customer harus diisi") if order.payment_term_id != partner.property_payment_term_id: raise UserError("Payment Term berbeda pada Master Data Customer") @@ -727,7 +727,7 @@ class SaleOrder(models.Model): partner = order.partner_id.parent_id or order.partner_id if not partner.property_payment_term_id: raise UserError("Payment Term pada Master Data Customer harus diisi") - if not partner.active_limit: + if not partner.active_limit and order.payment_term_id.id not in [27, 26]: raise UserError("Credit Limit pada Master Data Customer harus diisi") if order.payment_term_id != partner.property_payment_term_id: raise UserError("Payment Term berbeda pada Master Data Customer") -- cgit v1.2.3 From 55a7bd6000c93b19f70489e5393102854cceaa4b Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 7 Oct 2024 14:05:09 +0700 Subject: cr estimate shipping price envio --- indoteknik_custom/models/sale_order.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 265ffb9e..2cef531e 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -140,14 +140,42 @@ class SaleOrder(models.Model): def _compute_total_weight(self): for order in self: order.total_weight = sum(line.weight for line in order.order_line) + + def action_indoteknik_estimate_shipping(self): + if not self.real_shipping_id.kota_id.is_jabodetabek: + raise UserError('Estimasi ongkir hanya bisa dilakukan di kota Jabodetabek') + + total_weight = 0 + missing_weight_products = [] + + for line in self.order_line: + if line.weight: + total_weight += line.weight * line.product_uom_qty + line.product_id.weight = line.weight + else: + missing_weight_products.append(line.product_id.name) + + if missing_weight_products: + product_names = '
'.join(missing_weight_products) + self.message_post(body=f"Produk berikut tidak memiliki berat:
{product_names}") + + if total_weight == 0: + raise UserError("Tidak dapat mengestimasi ongkir tanpa berat yang valid.") + + if total_weight < 10: + total_weight = 10 + self.delivery_amt = total_weight * 3000 def action_estimate_shipping(self): + if self.carrier_id.id in [1, 151]: + self.action_indoteknik_estimate_shipping() + return total_weight = 0 missing_weight_products = [] for line in self.order_line: if line.weight: - total_weight += line.weight + total_weight += line.weight * line.product_uom_qty line.product_id.weight = line.weight else: missing_weight_products.append(line.product_id.name) -- cgit v1.2.3 From 53cb341f8184c3d74434f2b2d18d1bd984b57118 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 8 Oct 2024 09:06:49 +0700 Subject: cr po and validasi so --- indoteknik_custom/models/sale_order.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 2cef531e..d56a7946 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -727,10 +727,14 @@ class SaleOrder(models.Model): for order in self: order.order_line.validate_line() + term_days = 0 + for term_line in order.payment_term_id.line_ids: + term_days += term_line.days + partner = order.partner_id.parent_id or order.partner_id if not partner.property_payment_term_id: raise UserError("Payment Term pada Master Data Customer harus diisi") - if not partner.active_limit and order.payment_term_id.id not in [27, 26]: + if not partner.active_limit and term_days > 0: raise UserError("Credit Limit pada Master Data Customer harus diisi") if order.payment_term_id != partner.property_payment_term_id: raise UserError("Payment Term berbeda pada Master Data Customer") @@ -752,10 +756,15 @@ class SaleOrder(models.Model): for order in self: order.order_line.validate_line() + + term_days = 0 + for term_line in order.payment_term_id.line_ids: + term_days += term_line.days + partner = order.partner_id.parent_id or order.partner_id if not partner.property_payment_term_id: raise UserError("Payment Term pada Master Data Customer harus diisi") - if not partner.active_limit and order.payment_term_id.id not in [27, 26]: + if not partner.active_limit and term_days > 0: raise UserError("Credit Limit pada Master Data Customer harus diisi") if order.payment_term_id != partner.property_payment_term_id: raise UserError("Payment Term berbeda pada Master Data Customer") -- cgit v1.2.3 From 8512e5777d0fbe84f73ec061ac2afb90e7a474e6 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 8 Oct 2024 13:20:16 +0700 Subject: cr total weight --- indoteknik_custom/models/sale_order.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index d56a7946..c1c2c267 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -138,8 +138,14 @@ class SaleOrder(models.Model): total_weight = fields.Float(string='Total Weight', compute='_compute_total_weight') def _compute_total_weight(self): - for order in self: - order.total_weight = sum(line.weight for line in order.order_line) + total_weight = 0 + missing_weight_products = [] + + for line in self.order_line: + if line.weight: + total_weight += line.weight * line.product_uom_qty + + self.total_weight = total_weight def action_indoteknik_estimate_shipping(self): if not self.real_shipping_id.kota_id.is_jabodetabek: -- cgit v1.2.3 From 80433401aeba163a03f0f30902332331338b005f Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 15 Oct 2024 09:12:20 +0700 Subject: remove set npwp and sppkp while confirm sales order for disruption --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index c1c2c267..2e0b5775 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -943,7 +943,7 @@ class SaleOrder(models.Model): return self._create_approval_notification('Sales Manager') order.approval_status = 'approved' - order._set_sppkp_npwp_contact() + # order._set_sppkp_npwp_contact() order.calculate_line_no() order.send_notif_to_salesperson() # order.order_line.get_reserved_from() -- cgit v1.2.3 From 1833d42fe880ca3c63630c46d1b2e4f19e89c9ab Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 15 Oct 2024 09:20:19 +0700 Subject: disable update if not null in npwp sppkp contact while confirm so --- indoteknik_custom/models/sale_order.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 2e0b5775..e6382cd9 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -943,7 +943,7 @@ class SaleOrder(models.Model): return self._create_approval_notification('Sales Manager') order.approval_status = 'approved' - # order._set_sppkp_npwp_contact() + order._set_sppkp_npwp_contact() order.calculate_line_no() order.send_notif_to_salesperson() # order.order_line.get_reserved_from() @@ -1024,11 +1024,20 @@ class SaleOrder(models.Model): def _set_sppkp_npwp_contact(self): partner = self.partner_id.parent_id or self.partner_id - if not partner.sppkp or not partner.npwp or not partner.email or partner.customer_type: - partner.customer_type = self.customer_type - partner.npwp = self.npwp + if not partner.sppkp: partner.sppkp = self.sppkp + if not partner.npwp: + partner.npwp = self.npwp + if not partner.email: partner.email = self.email + if not partner.customer_type: + partner.customer_type = self.customer_type + + # if not partner.sppkp or not partner.npwp or not partner.email or partner.customer_type: + # partner.customer_type = self.customer_type + # partner.npwp = self.npwp + # partner.sppkp = self.sppkp + # partner.email = self.email def _compute_total_margin(self): for order in self: -- cgit v1.2.3 From 39b3e85ebcef9a02b3d6cb881d071c37ef45ac4f Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 16 Oct 2024 14:05:28 +0700 Subject: add field pareto_status --- indoteknik_custom/models/sale_order.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index e6382cd9..22130ac3 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -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): -- cgit v1.2.3 From 330dc374a9a15e4ad41b6829ad87a2a1d8264fff Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 18 Oct 2024 14:10:45 +0700 Subject: temporary comment update contact in sales order --- indoteknik_custom/models/sale_order.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 22130ac3..cb7d1782 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1314,7 +1314,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): @@ -1322,8 +1322,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 -- cgit v1.2.3 From eadc70481dd65dd7483aa2ae5c9bcc68bb274f3e Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 21 Oct 2024 09:19:50 +0700 Subject: fix bug vendor approval --- indoteknik_custom/models/sale_order.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index cb7d1782..891482cb 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -873,6 +873,9 @@ class SaleOrder(models.Model): }).send() def validate_different_vendor(self): + if self.vendor_approval_id and self.vendor_approval: + 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 self.vendor_approval_id and self.vendor_approval_id.state == 'draft': -- cgit v1.2.3 From c99e4d67c037a781b79e0ed198899d5f5c4a153b Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 22 Oct 2024 10:53:16 +0700 Subject: cr vendor approval --- indoteknik_custom/models/sale_order.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 891482cb..1ad08154 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -873,17 +873,16 @@ class SaleOrder(models.Model): }).send() def validate_different_vendor(self): - if self.vendor_approval_id and self.vendor_approval: - 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 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, -- cgit v1.2.3