diff options
| author | AndriFP <andrifebriyadiputra@gmail.com> | 2025-04-17 13:50:10 +0700 |
|---|---|---|
| committer | AndriFP <andrifebriyadiputra@gmail.com> | 2025-04-17 13:50:10 +0700 |
| commit | 984c3fe0d032dc0e37aae030b10658c310b9705d (patch) | |
| tree | a67d6f7ca0a8ef549d51d8e62f4e65fb7737edcc | |
| parent | 0ee640e0030441c204be6de3edc4184a37c85cd8 (diff) | |
(andri) Check + revisi add minimum dev amt & add log note after estimate shipping
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 16 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 108 |
2 files changed, 60 insertions, 64 deletions
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 04ee136c..451577c5 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -104,7 +104,7 @@ class ResPartner(models.Model): ('nonpkp', 'Non PKP') ]) sppkp = fields.Char(string="SPPKP", tracking=True) - npwp = fields.Char(string="npwp", tracking=True) + npwp = fields.Char(string="NPWP", tracking=True) nitku = fields.Char(string="NITKU", tracking=True) counter = fields.Integer(string="Counter", default=0) leadtime = fields.Integer(string="Leadtime", default=0) @@ -202,14 +202,14 @@ class ResPartner(models.Model): @api.constrains('npwp') def _check_npwp(self): - for rec in self: - if rec.npwp: - if not rec.npwp.isdigit(): + for record in self: + if record.npwp: + if not record.npwp.isdigit(): raise ValidationError("NPWP hanya boleh berisi angka.") - if len(rec.npwp) <= 15: - raise UserError("NPWP terlalu pendek. Minimal 15 digit.") - if len(rec.npwp) >= 16: - raise ValidationError("NPWP terlalu panjang. Maksimal 16 digit.") + if len(record.npwp) < 15: + raise ValidationError("Digit NPWP yang dimasukkan kurang dari batas minimal (15 digit)") + if len(record.npwp) > 16: + raise ValidationError("Digit NPWP yang dimasukkan lebih dari batas maksimal (16 digit)") def write(self, vals): # Fungsi rekursif untuk meng-update semua child, termasuk child dari child 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:<br/>" - f"<b>Layanan:</b> {first_option.name}<br/>" - f"<b>Deskripsi:</b> {dict(first_option._fields['name'].selection).get(first_option.name, first_option.name)}<br/>" - f"<b>ETD:</b> {first_option.etd} hari<br/>" - f"<b>Biaya:</b> Rp {first_option.price:,}" - ) self.message_post( - body=message, - message_type="comment", + body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}<br/>Detail Lain:<br/>" + f"{'<br/>'.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}<br/>Detail Lain:<br/>{'<br/>'.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: |
