diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-02-24 17:16:45 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-02-24 17:16:45 +0700 |
| commit | 1d2011c7b1b9766b0254479733b2ec226e8201bd (patch) | |
| tree | c6d604214853b0cfbc62c2588227fd40e4bbd4dc | |
| parent | 7df979b8d5312bb90d13d338f2a787dc35373f17 (diff) | |
add public holiday
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 15 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sale_order.py | 4 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 48 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 22 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 2 |
5 files changed, 57 insertions, 34 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 93ef305c..557215ea 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -7,18 +7,7 @@ import logging import math import json -_logger = logging.getLogger(__name__) - -def get_days_until_next_business_day(start_date=None, *args, **kwargs): - today = start_date or datetime.today().date() - offset = 0 # Counter jumlah hari yang ditambahkan - - while today.weekday() >= 5 : - today += timedelta(days=1) - offset += 1 - - return offset - +_logger = logging.getLogger(__name__) class Product(controller.Controller): @@ -88,7 +77,7 @@ class Product(controller.Controller): break start_date = datetime.today().date() - additional_days = get_days_until_next_business_day(start_date) + additional_days = request.env['sale.order'].get_days_until_next_business_day(start_date) # Jika semua loop selesai tanpa include_instant menjadi False return self.response({ diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 8b95ade8..4afeb21b 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -386,7 +386,8 @@ class SaleOrder(controller.Controller): 'note_website': [], 'voucher': [], 'source': [], - 'estimated_arrival_days': ['number', 'default:0'] + 'estimated_arrival_days': ['number', 'default:0'], + 'estimated_arrival_days_start': ['number', 'default:0'] }) if not params['valid']: @@ -416,6 +417,7 @@ class SaleOrder(controller.Controller): 'partner_purchase_order_file': params['value']['po_file'], 'delivery_amt': params['value']['delivery_amount'] * 1.10, 'estimated_arrival_days': params['value']['estimated_arrival_days'], + 'estimated_arrival_days_start': params['value']['estimated_arrival_days_start'], 'shipping_cost_covered': 'customer', 'shipping_paid_by': 'customer', 'carrier_id': params['value']['carrier_id'], diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index d0b57a3d..d956e93a 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -93,11 +93,13 @@ class SaleOrder(models.Model): applied_voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Applied Voucher', copy=False) amount_voucher_shipping_disc = fields.Float(string='Voucher Discount') source_id = fields.Many2one('utm.source', 'Source', domain="[('id', 'in', [32, 59, 60, 61])]", required=True) - estimated_arrival_days = fields.Integer('Estimated Arrival Days', default=0) + estimated_arrival_days = fields.Integer('Estimated Arrival To', default=0) + estimated_arrival_days_start = fields.Integer('Estimated Arrival From', default=0) email = fields.Char(string='Email') picking_iu_id = fields.Many2one('stock.picking', 'Picking IU') helper_by_id = fields.Many2one('res.users', 'Helper By') - eta_date = fields.Datetime(string='ETA Date', copy=False, compute='_compute_eta_date') + eta_date_start = fields.Datetime(string='ETA Date start', copy=False, compute='_compute_eta_start_date') + eta_date = fields.Datetime(string='ETA Date end', copy=False, compute='_compute_eta_date') flash_sale = fields.Boolean(string='Flash Sale', help='Data dari web') is_continue_transaction = fields.Boolean(string='Button Transaction', help='Data dari web') web_approval = fields.Selection([ @@ -146,9 +148,7 @@ class SaleOrder(models.Model): ]) estimated_ready_ship_date = fields.Datetime( string='ET Ready to Ship compute', - compute='_compute_etrts_date', - store=True - + compute='_compute_etrts_date' ) expected_ready_to_ship = fields.Datetime( string='ET Ready to Ship', @@ -156,7 +156,7 @@ class SaleOrder(models.Model): store=True ) shipping_method_picking = fields.Char(string='Shipping Method Picking', compute='_compute_shipping_method_picking') - + def _compute_shipping_method_picking(self): for order in self: if order.picking_ids: @@ -383,13 +383,43 @@ class SaleOrder(models.Model): rec.compute_fullfillment = True - @api.depends('date_order', 'estimated_arrival_days', 'state') + @api.depends('date_order', 'estimated_arrival_days', 'state', 'estimated_arrival_days_start') def _compute_eta_date(self): for rec in self: if rec.date_order and rec.state not in ['cancel'] and rec.estimated_arrival_days: rec.eta_date = rec.date_order + timedelta(days=rec.estimated_arrival_days) + rec.eta_date_start = rec.date_order + timedelta(days=rec.estimated_arrival_days_start) else: rec.eta_date = False + rec.eta_date_start = False + + @api.depends('date_order', 'state', 'estimated_arrival_days_start') + def _compute_eta_start_date(self): + for rec in self: + if rec.date_order and rec.state not in ['cancel'] and rec.estimated_arrival_days_start: + rec.eta_date_start = rec.date_order + timedelta(days=rec.estimated_arrival_days_start) + else: + rec.eta_date_start = False + + def get_days_until_next_business_day(self,start_date=None, *args, **kwargs): + today = start_date or datetime.today().date() + offset = 0 # Counter jumlah hari yang ditambahkan + holiday = self.env['hr.public.holiday'] + + while True : + today += timedelta(days=1) + offset += 1 + + if today.weekday() >= 5: + continue + + is_holiday = holiday.search([("start_date", "=", today)]) + if is_holiday: + continue + + break + + return offset @api.depends("order_line.product_id") def _compute_etrts_date(self): #Function to calculate Estimated Ready To Ship Date @@ -401,7 +431,7 @@ class SaleOrder(models.Model): max_slatime = max(max_slatime, slatime) if rec.date_order: - eta_date = datetime.now() + timedelta(days=max_slatime) + eta_date = rec.date_order + timedelta(days=self.get_days_until_next_business_day(rec.date_order)) + 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 @@ -1470,7 +1500,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._compute_etrts_date() + order._compute_etrts_date() # order._update_partner_details() return order diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 1690a4ed..be395cef 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -177,19 +177,19 @@ class StockPicking(models.Model): biteship_id = fields.Char(string="Biteship Respon ID") 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_ready_to_ship', store=True, default=False) + estimated_ready_ship_date = fields.Datetime(string='ET Ready to Ship', copy=False, related='sale_id.estimated_ready_ship_date') + countdown_hours = fields.Float(string='Countdown in Hours', compute='_compute_countdown_hours', 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): diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index b267eee4..4cc96cd2 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -68,6 +68,8 @@ <field name="compute_fullfillment" invisible="1"/> </field> <field name="tag_ids" position="after"> + <field name="eta_date_start"/> + <t t-esc="' to '"/> <field name="eta_date" readonly="1"/> <field name="expected_ready_to_ship" /> <field name="flash_sale"/> |
