From e9f38f540f92d6ef98b0153cbf17ce064932ad60 Mon Sep 17 00:00:00 2001 From: AndriFP Date: Tue, 15 Apr 2025 16:47:04 +0700 Subject: fix: add minimun delivery_amt + alert --- indoteknik_custom/models/sale_order.py | 80 ++++++++++++++++++++++++++++++++-- 1 file changed, 76 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 c83ffd61..36feb70b 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -315,8 +315,12 @@ class SaleOrder(models.Model): "sale_order_id": self.id, }) self.shipping_option_id = shipping_option.id - + def action_estimate_shipping(self): + # Pengecekan Minimum Delivery Amount + if self.delivery_amt < 5000: + raise UserError("Estimasi ongkos kirim belum mencapai jumlah minimum untuk pengiriman") + if self.carrier_id.id in [1, 151]: self.action_indoteknik_estimate_shipping() return @@ -366,10 +370,65 @@ class SaleOrder(models.Model): self.shipping_option_id = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1).id - self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Detail Lain:
{'
'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}") + # Jika perlu, tambahkan log atau tindakan lebih lanjut setelah peringatan else: raise UserError("Gagal mendapatkan estimasi ongkir.") + + # 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 > 0: + # 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.") + + # destination_subsdistrict_id = self.real_shipping_id.kecamatan_id.rajaongkir_id + # if not destination_subsdistrict_id: + # raise UserError("Gagal mendapatkan ID kota tujuan.") + + # result = self._call_rajaongkir_api(total_weight, destination_subsdistrict_id) + # if result: + # shipping_options = [] + # 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_options.append((service, description, etd, value, courier['code'])) + + # self.env["shipping.option"].search([('sale_order_id', '=', self.id)]).unlink() + + # for service, description, etd, value, provider in shipping_options: + # self.env["shipping.option"].create({ + # "name": service, + # "price": value, + # "provider": provider, + # "etd": etd, + # "sale_order_id": self.id, + # }) + + # self.shipping_option_id = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1).id + + # self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Detail Lain:
{'
'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}") + # else: + # raise UserError("Gagal mendapatkan estimasi ongkir.") + def _call_rajaongkir_api(self, total_weight, destination_subsdistrict_id): url = 'https://pro.rajaongkir.com/api/cost' headers = { @@ -670,13 +729,26 @@ class SaleOrder(models.Model): raise UserError('Email yang anda input kurang valid') # @api.constrains('delivery_amt', 'carrier_id', 'shipping_cost_covered') + def _validate_delivery_amt(self): + if self.delivery_amt < 5000: + raise UserError("Estimasi Ongkos Kirim belum memenuhi jumlah minimum untuk pengiriman.") + if self.delivery_amt < 1: - if(self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []): - if(self.carrier_id.id == 1): + if (self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []): + if self.carrier_id.id == 1: raise UserError('Untuk Kurir Indoteknik Delivery, Estimasi Ongkos Kirim Harus di isi') else: raise UserError('Untuk Shipping Covered Indoteknik, Estimasi Ongkos Kirim Harus di isi') + + + # def _validate_delivery_amt(self): + # if self.delivery_amt < 1: + # if(self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []): + # if(self.carrier_id.id == 1): + # raise UserError('Untuk Kurir Indoteknik Delivery, Estimasi Ongkos Kirim Harus di isi') + # else: + # raise UserError('Untuk Shipping Covered Indoteknik, Estimasi Ongkos Kirim Harus di isi') def override_allow_create_invoice(self): if not self.env.user.is_accounting: -- cgit v1.2.3 From 2dc56ffaf7e2e6d703eac32fd1213cf84b684915 Mon Sep 17 00:00:00 2001 From: AndriFP Date: Wed, 16 Apr 2025 10:25:39 +0700 Subject: (andri)add log note after estimate shipping success --- indoteknik_custom/models/sale_order.py | 129 +++++++++++++-------------------- 1 file changed, 51 insertions(+), 78 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 36feb70b..cc7b9851 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -315,12 +315,22 @@ class SaleOrder(models.Model): "sale_order_id": self.id, }) self.shipping_option_id = shipping_option.id + self.message_post( + body=( + f"Estimasi pengiriman Indoteknik berhasil:
" + f"Layanan: {shipping_option.name}
" + f"ETD: {shipping_option.etd}
" + f"Biaya: Rp {shipping_option.price:,}
" + f"Provider: {shipping_option.provider}" + ), + message_type="comment", + ) def action_estimate_shipping(self): # Pengecekan Minimum Delivery Amount if self.delivery_amt < 5000: raise UserError("Estimasi ongkos kirim belum mencapai jumlah minimum untuk pengiriman") - + if self.carrier_id.id in [1, 151]: self.action_indoteknik_estimate_shipping() return @@ -347,87 +357,50 @@ class SaleOrder(models.Model): raise UserError("Gagal mendapatkan ID kota tujuan.") result = self._call_rajaongkir_api(total_weight, destination_subsdistrict_id) - if result: - shipping_options = [] - 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_options.append((service, description, etd, value, courier['code'])) - - self.env["shipping.option"].search([('sale_order_id', '=', self.id)]).unlink() - - for service, description, etd, value, provider in shipping_options: - self.env["shipping.option"].create({ - "name": service, - "price": value, - "provider": provider, - "etd": etd, - "sale_order_id": self.id, - }) - - self.shipping_option_id = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1).id - # Jika perlu, tambahkan log atau tindakan lebih lanjut setelah peringatan + if not result: + raise UserError("Estimasi Ongkir gagal sebab pilihan kurir tidak terdaftar di RajaOngkir") + + shipping_options = [] + 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_options.append((service, description, etd, value, courier['code'])) + + # Hapus opsi shipping lama + self.env["shipping.option"].search([('sale_order_id', '=', self.id)]).unlink() + + # Simpan opsi shipping baru + for service, description, etd, value, provider in shipping_options: + self.env["shipping.option"].create({ + "name": service, + "price": value, + "provider": provider, + "etd": etd, + "sale_order_id": self.id, + }) + + # Set opsi shipping default + first_option = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1) + if first_option: + self.shipping_option_id = first_option.id + message = ( + f"Estimasi pengiriman berhasil:
" + f"Layanan: {first_option.name}
" + f"Deskripsi: {dict(first_option._fields['name'].selection).get(first_option.name, first_option.name)}
" + f"ETD: {first_option.etd} hari
" + f"Biaya: Rp {first_option.price:,}" + ) + self.message_post( + body=message, + message_type="comment", + ) else: raise UserError("Gagal mendapatkan estimasi ongkir.") - - # 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 > 0: - # 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.") - - # destination_subsdistrict_id = self.real_shipping_id.kecamatan_id.rajaongkir_id - # if not destination_subsdistrict_id: - # raise UserError("Gagal mendapatkan ID kota tujuan.") - - # result = self._call_rajaongkir_api(total_weight, destination_subsdistrict_id) - # if result: - # shipping_options = [] - # 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_options.append((service, description, etd, value, courier['code'])) - - # self.env["shipping.option"].search([('sale_order_id', '=', self.id)]).unlink() - - # for service, description, etd, value, provider in shipping_options: - # self.env["shipping.option"].create({ - # "name": service, - # "price": value, - # "provider": provider, - # "etd": etd, - # "sale_order_id": self.id, - # }) - - # self.shipping_option_id = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1).id - - # self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Detail Lain:
{'
'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}") - # else: - # raise UserError("Gagal mendapatkan estimasi ongkir.") def _call_rajaongkir_api(self, total_weight, destination_subsdistrict_id): url = 'https://pro.rajaongkir.com/api/cost' -- cgit v1.2.3 From 6ee875d5dad299ebcd17c16d6c3736cf881e53f4 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 16 Apr 2025 11:30:28 +0700 Subject: ppush --- 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 c83ffd61..97e3b5b0 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -472,7 +472,7 @@ class SaleOrder(models.Model): def _compute_date_kirim(self): for rec in self: - picking = self.env['stock.picking'].search([('sale_id', '=', rec.id), ('state', 'not in', ['cancel'])], order='date_doc_kirim desc', limit=1) + picking = self.env['stock.picking'].search([('sale_id', '=', rec.id), ('state', 'not in', ['cancel']), ('name', 'not ilike', 'BU/PICK/%')], order='date_doc_kirim desc', limit=1) rec.date_kirim_ril = picking.date_doc_kirim rec.date_status_done = picking.date_done rec.date_driver_arrival = picking.driver_arrival_date -- cgit v1.2.3 From 984c3fe0d032dc0e37aae030b10658c310b9705d Mon Sep 17 00:00:00 2001 From: AndriFP Date: Thu, 17 Apr 2025 13:50:10 +0700 Subject: (andri) Check + revisi add minimum dev amt & add log note after estimate shipping --- indoteknik_custom/models/sale_order.py | 108 ++++++++++++++++----------------- 1 file changed, 52 insertions(+), 56 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 cc7b9851..92581678 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -327,10 +327,6 @@ class SaleOrder(models.Model): ) def action_estimate_shipping(self): - # Pengecekan Minimum Delivery Amount - if self.delivery_amt < 5000: - raise UserError("Estimasi ongkos kirim belum mencapai jumlah minimum untuk pengiriman") - if self.carrier_id.id in [1, 151]: self.action_indoteknik_estimate_shipping() return @@ -357,50 +353,45 @@ class SaleOrder(models.Model): raise UserError("Gagal mendapatkan ID kota tujuan.") result = self._call_rajaongkir_api(total_weight, destination_subsdistrict_id) + if result: + shipping_options = [] + 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_options.append((service, description, etd, value, courier['code'])) + + self.env["shipping.option"].search([('sale_order_id', '=', self.id)]).unlink() - if not result: - raise UserError("Estimasi Ongkir gagal sebab pilihan kurir tidak terdaftar di RajaOngkir") - - shipping_options = [] - 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_options.append((service, description, etd, value, courier['code'])) - - # Hapus opsi shipping lama - self.env["shipping.option"].search([('sale_order_id', '=', self.id)]).unlink() - - # Simpan opsi shipping baru - for service, description, etd, value, provider in shipping_options: - self.env["shipping.option"].create({ - "name": service, - "price": value, - "provider": provider, - "etd": etd, - "sale_order_id": self.id, - }) + _logger.info(f"Shipping options: {shipping_options}") + + for service, description, etd, value, provider in shipping_options: + self.env["shipping.option"].create({ + "name": service, + "price": value, + "provider": provider, + "etd": etd, + "sale_order_id": self.id, + }) + + + self.shipping_option_id = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1).id + + _logger.info(f"Shipping option SO ID: {self.shipping_option_id}") - # Set opsi shipping default - first_option = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1) - if first_option: - self.shipping_option_id = first_option.id - message = ( - f"Estimasi pengiriman berhasil:
" - f"Layanan: {first_option.name}
" - f"Deskripsi: {dict(first_option._fields['name'].selection).get(first_option.name, first_option.name)}
" - f"ETD: {first_option.etd} hari
" - f"Biaya: Rp {first_option.price:,}" - ) self.message_post( - body=message, - message_type="comment", + body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Detail Lain:
" + f"{'
'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}", + message_type="comment" ) + + # self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Detail Lain:
{'
'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}", message_type="comment") + else: raise UserError("Gagal mendapatkan estimasi ongkir.") - + def _call_rajaongkir_api(self, total_weight, destination_subsdistrict_id): url = 'https://pro.rajaongkir.com/api/cost' @@ -702,26 +693,31 @@ class SaleOrder(models.Model): raise UserError('Email yang anda input kurang valid') # @api.constrains('delivery_amt', 'carrier_id', 'shipping_cost_covered') - def _validate_delivery_amt(self): - if self.delivery_amt < 5000: - raise UserError("Estimasi Ongkos Kirim belum memenuhi jumlah minimum untuk pengiriman.") + is_indoteknik = self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik' + is_active_id = not self.env.context.get('active_id', []) - if self.delivery_amt < 1: - if (self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []): + if is_indoteknik and is_active_id: + if self.delivery_amt == 0: if self.carrier_id.id == 1: - raise UserError('Untuk Kurir Indoteknik Delivery, Estimasi Ongkos Kirim Harus di isi') + raise UserError('Untuk Kurir Indoteknik Delivery, estimasi ongkos kirim belum diisi.') else: - raise UserError('Untuk Shipping Covered Indoteknik, Estimasi Ongkos Kirim Harus di isi') + raise UserError('Untuk Shipping Covered Indoteknik, estimasi ongkos kirim belum diisi.') + + if self.delivery_amt < 5000: + if self.carrier_id.id == 1: + raise UserError('Untuk Kurir Indoteknik Delivery, estimasi ongkos kirim belum memenuhi tarif minimum.') + else: + raise UserError('Untuk Shipping Covered Indoteknik, estimasi ongkos kirim belum memenuhi tarif minimum.') + + # if self.delivery_amt < 5000: + # if (self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []): + # if self.carrier_id.id == 1: + # raise UserError('Untuk Kurir Indoteknik Delivery, estimasi ongkos kirim belum memenuhi jumlah minimum.') + # else: + # raise UserError('Untuk Shipping Covered Indoteknik, estimasi ongkos kirim belum memenuhi jumlah minimum.') - # def _validate_delivery_amt(self): - # if self.delivery_amt < 1: - # if(self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []): - # if(self.carrier_id.id == 1): - # raise UserError('Untuk Kurir Indoteknik Delivery, Estimasi Ongkos Kirim Harus di isi') - # else: - # raise UserError('Untuk Shipping Covered Indoteknik, Estimasi Ongkos Kirim Harus di isi') def override_allow_create_invoice(self): if not self.env.user.is_accounting: -- cgit v1.2.3 From 2f16e84dcceec98e3dd49cbbbf57457d00989a04 Mon Sep 17 00:00:00 2001 From: AndriFP Date: Tue, 22 Apr 2025 12:28:04 +0700 Subject: (miqdad) add xpdc --- indoteknik_custom/models/sale_order.py | 79 +++++++++++++--------------------- 1 file changed, 29 insertions(+), 50 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 92581678..2061c686 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -67,6 +67,17 @@ class ShippingOption(models.Model): class SaleOrder(models.Model): _inherit = "sale.order" + ongkir_ke_xpdc = fields.Float(string='Ongkir ke Ekspedisi', help='Biaya ongkir ekspedisi', copy=False, index=True, tracking=3) + + metode_kirim_ke_xpdc = fields.Selection([ + ('indoteknik_deliv', 'Indoteknik Delivery'), + ('lalamove', 'Lalamove'), + ('grab', 'Grab'), + ('gojek', 'Gojek'), + ('deliveree', 'Deliveree'), + ('other', 'Other'), + ], string='Metode Kirim Ke Ekspedisi', copy=False, index=True, tracking=3) + koli_lines = fields.One2many('sales.order.koli', 'sale_order_id', string='Sales Order Koli', auto_join=True) fulfillment_line_v2 = fields.One2many('sales.order.fulfillment.v2', 'sale_order_id', string='Fullfillment2') fullfillment_line = fields.One2many('sales.order.fullfillment', 'sales_order_id', string='Fullfillment') @@ -315,17 +326,7 @@ class SaleOrder(models.Model): "sale_order_id": self.id, }) self.shipping_option_id = shipping_option.id - self.message_post( - body=( - f"Estimasi pengiriman Indoteknik berhasil:
" - f"Layanan: {shipping_option.name}
" - f"ETD: {shipping_option.etd}
" - f"Biaya: Rp {shipping_option.price:,}
" - f"Provider: {shipping_option.provider}" - ), - message_type="comment", - ) - + def action_estimate_shipping(self): if self.carrier_id.id in [1, 151]: self.action_indoteknik_estimate_shipping() @@ -364,8 +365,6 @@ class SaleOrder(models.Model): shipping_options.append((service, description, etd, value, courier['code'])) self.env["shipping.option"].search([('sale_order_id', '=', self.id)]).unlink() - - _logger.info(f"Shipping options: {shipping_options}") for service, description, etd, value, provider in shipping_options: self.env["shipping.option"].create({ @@ -375,23 +374,12 @@ class SaleOrder(models.Model): "etd": etd, "sale_order_id": self.id, }) - self.shipping_option_id = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1).id - _logger.info(f"Shipping option SO ID: {self.shipping_option_id}") - - self.message_post( - body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Detail Lain:
" - f"{'
'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}", - message_type="comment" - ) - - # self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Detail Lain:
{'
'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}", message_type="comment") - + self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Detail Lain:
{'
'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}") else: raise UserError("Gagal mendapatkan estimasi ongkir.") - def _call_rajaongkir_api(self, total_weight, destination_subsdistrict_id): url = 'https://pro.rajaongkir.com/api/cost' @@ -495,7 +483,7 @@ class SaleOrder(models.Model): def _compute_date_kirim(self): for rec in self: - picking = self.env['stock.picking'].search([('sale_id', '=', rec.id), ('state', 'not in', ['cancel'])], order='date_doc_kirim desc', limit=1) + picking = self.env['stock.picking'].search([('sale_id', '=', rec.id), ('state', 'not in', ['cancel']), ('name', 'not ilike', 'BU/PICK/%')], order='date_doc_kirim desc', limit=1) rec.date_kirim_ril = picking.date_doc_kirim rec.date_status_done = picking.date_done rec.date_driver_arrival = picking.driver_arrival_date @@ -694,30 +682,12 @@ class SaleOrder(models.Model): # @api.constrains('delivery_amt', 'carrier_id', 'shipping_cost_covered') def _validate_delivery_amt(self): - is_indoteknik = self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik' - is_active_id = not self.env.context.get('active_id', []) - - if is_indoteknik and is_active_id: - if self.delivery_amt == 0: - if self.carrier_id.id == 1: - raise UserError('Untuk Kurir Indoteknik Delivery, estimasi ongkos kirim belum diisi.') - else: - raise UserError('Untuk Shipping Covered Indoteknik, estimasi ongkos kirim belum diisi.') - - if self.delivery_amt < 5000: - if self.carrier_id.id == 1: - raise UserError('Untuk Kurir Indoteknik Delivery, estimasi ongkos kirim belum memenuhi tarif minimum.') + if self.delivery_amt < 1: + if(self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []): + if(self.carrier_id.id == 1): + raise UserError('Untuk Kurir Indoteknik Delivery, Estimasi Ongkos Kirim Harus di isi') else: - raise UserError('Untuk Shipping Covered Indoteknik, estimasi ongkos kirim belum memenuhi tarif minimum.') - - - # if self.delivery_amt < 5000: - # if (self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []): - # if self.carrier_id.id == 1: - # raise UserError('Untuk Kurir Indoteknik Delivery, estimasi ongkos kirim belum memenuhi jumlah minimum.') - # else: - # raise UserError('Untuk Shipping Covered Indoteknik, estimasi ongkos kirim belum memenuhi jumlah minimum.') - + raise UserError('Untuk Shipping Covered Indoteknik, Estimasi Ongkos Kirim Harus di isi') def override_allow_create_invoice(self): if not self.env.user.is_accounting: @@ -1467,12 +1437,21 @@ class SaleOrder(models.Model): # partner.npwp = self.npwp # partner.sppkp = self.sppkp # partner.email = self.email - + def _compute_total_margin(self): for order in self: total_margin = sum(line.item_margin for line in order.order_line if line.product_id) + #hitung nek onk + if order.ongkir_ke_xpdc: + total_margin -= order.ongkir_ke_xpdc + order.total_margin = total_margin + # def _compute_total_margin(self): + # for order in self: + # total_margin = sum(line.item_margin for line in order.order_line if line.product_id) + # order.total_margin = total_margin + def _compute_total_percent_margin(self): for order in self: if order.amount_untaxed == 0: -- cgit v1.2.3 From 71e47cc88e250600c2975a114dd420f27fda36b3 Mon Sep 17 00:00:00 2001 From: AndriFP Date: Tue, 22 Apr 2025 12:45:44 +0700 Subject: (andri) change min dev amt from 5000 to 100 --- 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 92581678..37f767ec 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -704,7 +704,7 @@ class SaleOrder(models.Model): else: raise UserError('Untuk Shipping Covered Indoteknik, estimasi ongkos kirim belum diisi.') - if self.delivery_amt < 5000: + if self.delivery_amt < 100: if self.carrier_id.id == 1: raise UserError('Untuk Kurir Indoteknik Delivery, estimasi ongkos kirim belum memenuhi tarif minimum.') else: -- cgit v1.2.3 From 3f0a246d364a07f8c61eafeefcee7b37232a5933 Mon Sep 17 00:00:00 2001 From: AndriFP Date: Wed, 23 Apr 2025 14:57:14 +0700 Subject: (miqdad) rev add xpdc --- indoteknik_custom/models/sale_order.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 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 2061c686..bdb79fdf 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1438,19 +1438,6 @@ class SaleOrder(models.Model): # partner.sppkp = self.sppkp # partner.email = self.email - def _compute_total_margin(self): - for order in self: - total_margin = sum(line.item_margin for line in order.order_line if line.product_id) - #hitung nek onk - if order.ongkir_ke_xpdc: - total_margin -= order.ongkir_ke_xpdc - - order.total_margin = total_margin - - # def _compute_total_margin(self): - # for order in self: - # total_margin = sum(line.item_margin for line in order.order_line if line.product_id) - # order.total_margin = total_margin def _compute_total_percent_margin(self): for order in self: @@ -1768,4 +1755,13 @@ class SaleOrder(models.Model): self._validate_delivery_amt() if any(field in vals for field in ["order_line", "client_order_ref"]): self._calculate_etrts_date() - return res \ No newline at end of file + return res + + def _compute_total_margin(self): + for order in self: + total_margin = sum(line.item_margin for line in order.order_line if line.product_id) + #hitung nek onk + if order.ongkir_ke_xpdc: + total_margin -= order.ongkir_ke_xpdc + + order.total_margin = total_margin \ No newline at end of file -- cgit v1.2.3 From f710d62fcb33e43a832d18b28baa4641f9fb65a8 Mon Sep 17 00:00:00 2001 From: AndriFP Date: Wed, 23 Apr 2025 15:39:46 +0700 Subject: (miqdad) Fix conflict Xpdc --- indoteknik_custom/models/sale_order.py | 76 ++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 18 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 bdb79fdf..6b603146 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -326,7 +326,17 @@ class SaleOrder(models.Model): "sale_order_id": self.id, }) self.shipping_option_id = shipping_option.id - + self.message_post( + body=( + f"Estimasi pengiriman Indoteknik berhasil:
" + f"Layanan: {shipping_option.name}
" + f"ETD: {shipping_option.etd}
" + f"Biaya: Rp {shipping_option.price:,}
" + f"Provider: {shipping_option.provider}" + ), + message_type="comment", + ) + def action_estimate_shipping(self): if self.carrier_id.id in [1, 151]: self.action_indoteknik_estimate_shipping() @@ -365,6 +375,8 @@ class SaleOrder(models.Model): shipping_options.append((service, description, etd, value, courier['code'])) self.env["shipping.option"].search([('sale_order_id', '=', self.id)]).unlink() + + _logger.info(f"Shipping options: {shipping_options}") for service, description, etd, value, provider in shipping_options: self.env["shipping.option"].create({ @@ -374,12 +386,23 @@ class SaleOrder(models.Model): "etd": etd, "sale_order_id": self.id, }) + self.shipping_option_id = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1).id - self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Detail Lain:
{'
'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}") + _logger.info(f"Shipping option SO ID: {self.shipping_option_id}") + + self.message_post( + body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Detail Lain:
" + f"{'
'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}", + message_type="comment" + ) + + # self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}
Detail Lain:
{'
'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}", message_type="comment") + else: raise UserError("Gagal mendapatkan estimasi ongkir.") + def _call_rajaongkir_api(self, total_weight, destination_subsdistrict_id): url = 'https://pro.rajaongkir.com/api/cost' @@ -483,7 +506,7 @@ class SaleOrder(models.Model): def _compute_date_kirim(self): for rec in self: - picking = self.env['stock.picking'].search([('sale_id', '=', rec.id), ('state', 'not in', ['cancel']), ('name', 'not ilike', 'BU/PICK/%')], order='date_doc_kirim desc', limit=1) + picking = self.env['stock.picking'].search([('sale_id', '=', rec.id), ('state', 'not in', ['cancel'])], order='date_doc_kirim desc', limit=1) rec.date_kirim_ril = picking.date_doc_kirim rec.date_status_done = picking.date_done rec.date_driver_arrival = picking.driver_arrival_date @@ -682,12 +705,30 @@ class SaleOrder(models.Model): # @api.constrains('delivery_amt', 'carrier_id', 'shipping_cost_covered') def _validate_delivery_amt(self): - if self.delivery_amt < 1: - if(self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []): - if(self.carrier_id.id == 1): - raise UserError('Untuk Kurir Indoteknik Delivery, Estimasi Ongkos Kirim Harus di isi') + is_indoteknik = self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik' + is_active_id = not self.env.context.get('active_id', []) + + if is_indoteknik and is_active_id: + if self.delivery_amt == 0: + if self.carrier_id.id == 1: + raise UserError('Untuk Kurir Indoteknik Delivery, estimasi ongkos kirim belum diisi.') + else: + raise UserError('Untuk Shipping Covered Indoteknik, estimasi ongkos kirim belum diisi.') + + if self.delivery_amt < 100: + if self.carrier_id.id == 1: + raise UserError('Untuk Kurir Indoteknik Delivery, estimasi ongkos kirim belum memenuhi tarif minimum.') else: - raise UserError('Untuk Shipping Covered Indoteknik, Estimasi Ongkos Kirim Harus di isi') + raise UserError('Untuk Shipping Covered Indoteknik, estimasi ongkos kirim belum memenuhi tarif minimum.') + + + # if self.delivery_amt < 5000: + # if (self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []): + # if self.carrier_id.id == 1: + # raise UserError('Untuk Kurir Indoteknik Delivery, estimasi ongkos kirim belum memenuhi jumlah minimum.') + # else: + # raise UserError('Untuk Shipping Covered Indoteknik, estimasi ongkos kirim belum memenuhi jumlah minimum.') + def override_allow_create_invoice(self): if not self.env.user.is_accounting: @@ -1437,7 +1478,15 @@ class SaleOrder(models.Model): # partner.npwp = self.npwp # partner.sppkp = self.sppkp # partner.email = self.email + + def _compute_total_margin(self): + for order in self: + total_margin = sum(line.item_margin for line in order.order_line if line.product_id) + #hitung nek onk + if order.ongkir_ke_xpdc: + total_margin -= order.ongkir_ke_xpdc + order.total_margin = total_margin def _compute_total_percent_margin(self): for order in self: @@ -1755,13 +1804,4 @@ class SaleOrder(models.Model): self._validate_delivery_amt() if any(field in vals for field in ["order_line", "client_order_ref"]): self._calculate_etrts_date() - return res - - def _compute_total_margin(self): - for order in self: - total_margin = sum(line.item_margin for line in order.order_line if line.product_id) - #hitung nek onk - if order.ongkir_ke_xpdc: - total_margin -= order.ongkir_ke_xpdc - - order.total_margin = total_margin \ No newline at end of file + return res \ No newline at end of file -- cgit v1.2.3 From 5f78d57ced0957b5f05e590de67a4b966b22e85b Mon Sep 17 00:00:00 2001 From: AndriFP Date: Wed, 23 Apr 2025 15:46:28 +0700 Subject: (miqdad) fix conflict Xpdc --- indoteknik_custom/models/sale_order.py | 1 - 1 file changed, 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 6b603146..13646847 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1482,7 +1482,6 @@ class SaleOrder(models.Model): def _compute_total_margin(self): for order in self: total_margin = sum(line.item_margin for line in order.order_line if line.product_id) - #hitung nek onk if order.ongkir_ke_xpdc: total_margin -= order.ongkir_ke_xpdc -- cgit v1.2.3 From 4706b80d3d3b1e55c198d2b4cfb93f7fa47c9732 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 24 Apr 2025 13:49:35 +0700 Subject: validation duplicate barcode product and barcode box, cr date doc kirim, validation duplicate product id on so line --- indoteknik_custom/models/sale_order.py | 10 ++++++++++ 1 file changed, 10 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 39d6fd0b..02d61387 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1069,7 +1069,16 @@ class SaleOrder(models.Model): raise UserError("Product BOM belum dikonfirmasi di Manufacturing Orders. Silakan hubungi MD.") else: raise UserError("Product BOM tidak di temukan di manufacturing orders, silahkan hubungi MD") + + def check_duplicate_product(self): + for order in self: + for line in order.order_line: + search_product = self.env['sale.order.line'].search([('product_id', '=', line.product_id.id), ('order_id', '=', order.id)]) + if len(search_product) > 1: + raise UserError("Terdapat DUPLIKASI data pada Product {}".format(line.product_id.display_name)) + def sale_order_approve(self): + self.check_duplicate_product() self.check_product_bom() self.check_credit_limit() self.check_limit_so_to_invoice() @@ -1310,6 +1319,7 @@ class SaleOrder(models.Model): def action_confirm(self): for order in self: + order.check_duplicate_product() order.check_product_bom() order.check_credit_limit() order.check_limit_so_to_invoice() -- cgit v1.2.3