diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-09-23 17:27:24 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-09-23 17:27:24 +0700 |
| commit | a9c6b59debbde9053b517f98402a9414779f75ce (patch) | |
| tree | 94d0f8a59c50415f5296f28d677c3136496e1e8d | |
| parent | 7d09b515d62c9578301d3365d441958889aedc0f (diff) | |
| parent | 25f0261dac43b55d674193bd00fbadcad2706c08 (diff) | |
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into odoo-backup
merge
| -rw-r--r-- | indoteknik_custom/models/refund_sale_order.py | 8 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 88 |
2 files changed, 74 insertions, 22 deletions
diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 687acd6d..eab25452 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -902,6 +902,14 @@ class RefundSaleOrder(models.Model): for rec in self: if not is_fat: raise UserError("Hanya Finance yang dapat mengkonfirmasi pembayaran refund.") + is_journal = self.env['account.move'].search([ + ('refund_id', '=', rec.id), + ('state', '=', 'posted') + ]) + if not is_journal: + raise UserError("Journal Payment Refund belum dibuat, buat Journal Payment Refund sebelum confirm refund.") + if is_journal and rec.amount_refund != sum(is_journal.mapped('amount_total_signed')): + raise UserError("Total Refund dengan Total Journal Harus Sama.") if rec.status_payment == 'pending': rec.status_payment = 'done' rec.refund_date = fields.Date.context_today(self) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 39830ffc..02ceb62b 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1700,57 +1700,101 @@ class SaleOrder(models.Model): # .format(eta_minimum.strftime('%d-%m-%Y'), eta_minimum.strftime('%d-%m-%Y')) # ) + # def _validate_expected_ready_ship_date(self): + # """ + # Pastikan expected_ready_to_ship tidak lebih awal dari SLA minimum. + # Dipanggil setiap onchange / simpan SO. + # """ + # for rec in self: + # # ───────────────────────────────────────────────────── + # # 1. Hanya validasi kalau field sudah terisi + # # (quotation baru / belum ada tanggal → abaikan) + # # ───────────────────────────────────────────────────── + # if not rec.expected_ready_to_ship: + # continue + # + # current_date = datetime.now() + # + # # ───────────────────────────────────────────────────── + # # 2. Hitung SLA berdasarkan product lines (jika ada) + # # ───────────────────────────────────────────────────── + # products = rec.order_line + # if products: + # sla_data = rec.calculate_sla_by_vendor(products) + # max_sla_time = sla_data.get('slatime', 1) + # else: + # # belum ada item → gunakan default 1 hari + # max_sla_time = 1 + # + # # offset hari libur / weekend + # offset, is3pm = rec.get_days_until_next_business_day(current_date) + # min_days = max_sla_time + offset - 1 + # eta_minimum = current_date + timedelta(days=min_days) + # + # # ───────────────────────────────────────────────────── + # # 3. Validasi - raise error bila terlalu cepat + # # ───────────────────────────────────────────────────── + # if rec.expected_ready_to_ship.date() < eta_minimum.date(): + # # set otomatis ke tanggal minimum supaya user tidak perlu + # # menekan Save dua kali + # rec.expected_ready_to_ship = eta_minimum + # + # raise ValidationError( + # _("Tanggal 'Expected Ready to Ship' tidak boleh " + # "lebih kecil dari %(tgl)s. Mohon pilih minimal %(tgl)s.") + # % {'tgl': eta_minimum.strftime('%d-%m-%Y')} + # ) + # else: + # # sinkronkan ke field commitment_date + # rec.commitment_date = rec.expected_ready_to_ship + def _validate_expected_ready_ship_date(self): """ Pastikan expected_ready_to_ship tidak lebih awal dari SLA minimum. Dipanggil setiap onchange / simpan SO. """ for rec in self: - # ───────────────────────────────────────────────────── - # 1. Hanya validasi kalau field sudah terisi - # (quotation baru / belum ada tanggal → abaikan) - # ───────────────────────────────────────────────────── if not rec.expected_ready_to_ship: continue - current_date = datetime.now() + # ADDED: gunakan "sekarang" lokal user, bukan datetime.now() server + current_date = fields.Datetime.context_timestamp(rec, fields.Datetime.now()) - # ───────────────────────────────────────────────────── - # 2. Hitung SLA berdasarkan product lines (jika ada) - # ───────────────────────────────────────────────────── + # Hitung SLA products = rec.order_line if products: sla_data = rec.calculate_sla_by_vendor(products) max_sla_time = sla_data.get('slatime', 1) else: - # belum ada item → gunakan default 1 hari max_sla_time = 1 - # offset hari libur / weekend + # offset hari libur/weekend offset, is3pm = rec.get_days_until_next_business_day(current_date) min_days = max_sla_time + offset - 1 eta_minimum = current_date + timedelta(days=min_days) - # ───────────────────────────────────────────────────── - # 3. Validasi - raise error bila terlalu cepat - # ───────────────────────────────────────────────────── - if rec.expected_ready_to_ship.date() < eta_minimum.date(): - # set otomatis ke tanggal minimum supaya user tidak perlu - # menekan Save dua kali - rec.expected_ready_to_ship = eta_minimum + if rec._fields['expected_ready_to_ship'].type == 'date': + exp_date_local = rec.expected_ready_to_ship + else: + exp_date_local = fields.Datetime.context_timestamp( + rec, rec.expected_ready_to_ship + ).date() + + if exp_date_local < eta_minimum.date(): + # (opsional) auto-set ke minimum → konversi balik ke UTC naive bila field Datetime + if rec._fields['expected_ready_to_ship'].type == 'date': + rec.expected_ready_to_ship = eta_minimum.date() + else: + rec.expected_ready_to_ship = eta_minimum.astimezone(pytz.UTC).replace(tzinfo=None) raise ValidationError( _("Tanggal 'Expected Ready to Ship' tidak boleh " - "lebih kecil dari %(tgl)s. Mohon pilih minimal %(tgl)s.") + "lebih kecil dari %(tgl)s. Mohon pilih minimal %(tgl)s.") % {'tgl': eta_minimum.strftime('%d-%m-%Y')} ) else: - # sinkronkan ke field commitment_date rec.commitment_date = rec.expected_ready_to_ship - - - @api.onchange('expected_ready_to_ship') #Hangle Onchange form Expected Ready to Ship def _onchange_expected_ready_ship_date(self): self._validate_expected_ready_ship_date() |
