diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-02-13 11:20:11 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-02-13 11:20:11 +0700 |
| commit | 6a1b03cbd12931784aee8226ed5f163dcae42081 (patch) | |
| tree | 7a8c528d4dda29a7630d8603b2d87fadea4cb07a | |
| parent | d539aedf0b1f7a6cfbd87b9d167833c6c9ea68ee (diff) | |
biteship
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 35 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 46 |
2 files changed, 45 insertions, 36 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index cae99447..c6f8adc4 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -145,13 +145,13 @@ class SaleOrder(models.Model): ('NP', 'Non Pareto') ]) estimated_ready_ship_date = fields.Datetime( - string='ET Ready to Ship', + string='ET Ready to Ship compute', compute='_compute_etrts_date', store=True ) expected_ready_to_ship = fields.Datetime( - string='ET Ready to Ship FIX', + string='ET Ready to Ship', copy=False, store=True ) @@ -394,9 +394,26 @@ class SaleOrder(models.Model): if rec.date_order: eta_date = datetime.now() + timedelta(days=max_slatime) rec.estimated_ready_ship_date = eta_date + rec.commitment_date = eta_date # Jika expected_ready_to_ship kosong, set nilai default if not rec.expected_ready_to_ship: rec.expected_ready_to_ship = eta_date + + @api.onchange('expected_ready_to_ship') #Hangle Onchange form Expected Ready to Ship + def _onchange_expected_ready_ship_date(self): + for rec in self: + if rec.expected_ready_to_ship and rec.estimated_ready_ship_date: + # Hanya membandingkan tanggal saja, tanpa jam + expected_date = rec.expected_ready_to_ship.date() + estimated_date = rec.estimated_ready_ship_date.date() + + if expected_date < estimated_date: + rec.expected_ready_to_ship = rec.estimated_ready_ship_date + rec.commitment_date = rec.estimated_ready_ship_date + raise ValidationError( + "Tanggal 'Expected Ready to Ship' tidak boleh lebih kecil dari {}. Mohon pilih tanggal minimal {}." + .format(estimated_date.strftime('%d-%m-%Y'), estimated_date.strftime('%d-%m-%Y')) + ) def _set_etrts_date(self): for order in self: @@ -598,20 +615,6 @@ class SaleOrder(models.Model): line_no += 1 line.line_no = line_no - @api.onchange('expected_ready_to_ship') #Hangle Onchange form Expected Ready to Ship - def _onchange_expected_ready_ship_date(self): - for rec in self: - if rec.expected_ready_to_ship and rec.estimated_ready_ship_date: - # Hanya membandingkan tanggal saja, tanpa jam - expected_date = rec.expected_ready_to_ship.date() - estimated_date = rec.estimated_ready_ship_date.date() - - if expected_date < estimated_date: - rec.expected_ready_to_ship = rec.estimated_ready_ship_date - raise ValidationError( - "Tanggal 'Expected Ready to Ship' tidak boleh lebih kecil dari {}. Mohon pilih tanggal minimal {}." - .format(estimated_date.strftime('%d-%m-%Y'), estimated_date.strftime('%d-%m-%Y')) - ) def write(self, vals): res = super(SaleOrder, self).write(vals) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index f766dc3f..e7d9dbd5 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -170,18 +170,18 @@ class StockPicking(models.Model): biteship_tracking_id = fields.Char(string="Biteship Trackcking ID") biteship_waybill_id = fields.Char(string="Biteship Waybill ID") estimated_ready_ship_date = fields.Datetime(string='ET Ready to Ship', copy=False, store=True, related='sale_id.estimated_ready_ship_date') - countdown_hours = fields.Float(string='Countdown in Hours', compute='_compute_countdown_hours', store=True, default=False) + countdown_hours = fields.Float(string='Countdown in Hours', compute='_compute_countdown_ready_to_ship', store=True, default=False) countdown_ready_to_ship = fields.Char(string='Countdown Ready to Ship', compute='_compute_countdown_ready_to_ship') - @api.depends('estimated_ready_ship_date', 'state') - def _compute_countdown_hours(self): - for record in self: - if record.state in ('cancel', 'done') or not record.estimated_ready_ship_date: - # Gunakan nilai yang sangat besar sebagai placeholder - record.countdown_hours = 999999 - else: - delta = record.estimated_ready_ship_date - waktu.now() - record.countdown_hours = delta.total_seconds() / 3600 + # @api.depends('estimated_ready_ship_date', 'state') + # def _compute_countdown_hours(self): + # for record in self: + # if record.state in ('cancel', 'done') or not record.estimated_ready_ship_date: + # # Gunakan nilai yang sangat besar sebagai placeholder + # record.countdown_hours = 999999 + # else: + # delta = record.estimated_ready_ship_date - waktu.now() + # record.countdown_hours = delta.total_seconds() / 3600 @api.depends('estimated_ready_ship_date', 'state') def _compute_countdown_ready_to_ship(self): @@ -194,6 +194,7 @@ class StockPicking(models.Model): days = delta.days hours, remainder = divmod(delta.seconds, 3600) record.countdown_ready_to_ship = f"{days} days, {hours} hours" + record.countdown_hours = delta.total_seconds() / 3600 else: record.countdown_ready_to_ship = False @@ -351,7 +352,7 @@ class StockPicking(models.Model): picking.tracking_by = self.env.user.id ata_at_str = data.get("ata_at") envio_ata = self._convert_to_datetime(data.get("ata_at")) - + picking.driver_arrival_date = envio_ata if data.get("status") != 'delivered': picking.driver_arrival_date = False @@ -367,7 +368,7 @@ class StockPicking(models.Model): # Mencari data sale.order.line berdasarkan sale_id products = self.env['sale.order.line'].search([('order_id', '=', self.sale_id.id)]) - + # Fungsi untuk membangun items_data dari order lines def build_items_data(lines): return [{ @@ -411,7 +412,8 @@ class StockPicking(models.Model): "destination_contact_phone": self.real_shipping_id.phone or self.real_shipping_id.mobile, "destination_address": self.real_shipping_id.street, "destination_postal_code": self.real_shipping_id.zip, - "courier_type": "reg", + "origin_note": "BELAKANG INDOMARET", + "courier_type": self.sale_id.delivery_service_type or "reg", "courier_company": self.carrier_id.name.lower(), "delivery_type": "now", "destination_postal_code": self.real_shipping_id.zip, @@ -421,11 +423,15 @@ class StockPicking(models.Model): # Cek jika pengiriman instant atau same_day if self.sale_id.delivery_service_type and ("instant" in self.sale_id.delivery_service_type or "same_day" in self.sale_id.delivery_service_type): payload.update({ - "origin_note": "BELAKANG INDOMARET", - "courier_company": self.carrier_id.name.lower(), - "courier_type": self.sale_id.delivery_service_type, - "delivery_type": "now", - "items": items_data_instant # Gunakan items untuk instant + "origin_coordinate" :{ + "latitude": -6.3031123, + "longitude" : 106.7794934999 + }, + "destination_coordinate" : { + "latitude": self.real_shipping_id.latitude, + "longitude": self.real_shipping_id.longtitude, + }, + "items": items_data_instant }) headers = { @@ -440,8 +446,8 @@ class StockPicking(models.Model): data = response.json() self.biteship_id = data.get("id", "") - self.biteship_tracking_id = data.get("tracking_id", "") - self.biteship_waybill_id = data.get("waybill_id", "") + self.biteship_tracking_id = data.get("courier", {}).get("tracking_id", "") + self.biteship_waybill_id = data.get("courier", {}).get("waybill_id", "") return data else: |
