diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-02-28 09:55:08 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-02-28 09:55:08 +0700 |
| commit | d5e40546164b98fd9f819bc4f65f53d8b7c3c7f4 (patch) | |
| tree | ad0f4b268d784a2fe97e002baa1c5fd91dec228e | |
| parent | 62caad158a936eee9a0b85fd4df0c664374b6bfb (diff) | |
sequance
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 105 | ||||
| -rw-r--r-- | indoteknik_custom/views/stock_picking.xml | 6 |
2 files changed, 87 insertions, 24 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 605452e3..696d25db 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -23,6 +23,8 @@ _biteship_api_key = "biteship_test.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1l class StockPicking(models.Model): _inherit = 'stock.picking' + _order = 'final_seq ASC' + check_product_lines = fields.One2many('check.product', 'picking_id', string='Check Product', auto_join=True) barcode_product_lines = fields.One2many('barcode.product', 'picking_id', string='Barcode Product', auto_join=True) is_internal_use = fields.Boolean('Internal Use', help='flag which is internal use or not') @@ -178,33 +180,92 @@ 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, 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): + countdown_hours = fields.Float(string='Countdown in Hours', compute='_callculate_sequance', default=False, store=False, compute_sudo=False) + countdown_ready_to_ship = fields.Char(string='Countdown Ready to Ship', compute='_callculate_sequance', store=False, compute_sudo=False) + final_seq_tmp = fields.Float(string='Sequance Order in hours', store=True, compute_sudo=True) + final_seq = fields.Float(string='Sequance Order', related='final_seq_tmp', index=True) + + execution_date = fields.Float( + string='Time Remainder by date Reserved', + store=True, # Menyimpan hasil ke database + ) + def _compute_execution_date_by_date_reserved(self, date_reserved): 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 - + try: + if record.date_reserved and record.state not in ('cancel', 'done'): + date_reserved = record.date_reserved + timedelta(days=1) + time_diff = (date_reserved - waktu.now()).total_seconds() / 3600 + record.execution_date = time_diff + else: + record.execution_date = 99999999999 # Kosongkan jika tidak memenuhi kondisi + + except Exception as e: + error = f"Error calculating sequance {str(e)}" + _logger.error(f"Error calculating sequance {self.id}: {str(e)}") + return { 'error': str(e) } + + + # @api.depends('date_reserved') + # def _callculate_final_sequance(self): + # filtered_records = self.filtered(lambda r: r.estimated_ready_ship_date and r.date_reserved and r.state not in ('cancel', 'done')) + # for record in filtered_records: + # estimated_by_erts = (record.estimated_ready_ship_date - waktu.now()).total_seconds() / 3600 + # estimated_by_date = (record.date_reserved - waktu.now()).total_seconds() / 3600 + # record.final_seq_tmp = min(estimated_by_erts, estimated_by_date) + + # (self - filtered_records).write({'final_seq_tmp': 99999999999}) + + @api.depends('estimated_ready_ship_date', 'state') - def _compute_countdown_ready_to_ship(self): + def _callculate_sequance(self): for record in self: - if record.state in ('cancel', 'done'): - record.countdown_ready_to_ship = False - else: - if record.estimated_ready_ship_date: - delta = record.estimated_ready_ship_date - waktu.now() - 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 + try : + if record.estimated_ready_ship_date and record.state not in ('cancel', 'done'): + rts = record.estimated_ready_ship_date - waktu.now() + rts_days = rts.days + rts_hours = divmod(rts.seconds, 3600) + + estimated_by_erts = rts.total_seconds() / 3600 + + record.countdown_ready_to_ship = f"{rts_days} days, {rts_hours} hours" + record.countdown_hours = estimated_by_erts + record.final_seq = estimated_by_erts else: + + record.countdown_hours = 999999999999 record.countdown_ready_to_ship = False + except Exception as e : + error = str(e) + _logger.error(f"Error calculating sequance {self.id}: {str(e)}") + + print(str(e)) + return { 'error': str(e) } + + + # @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): + # for record in self: + # if record.state in ('cancel', 'done'): + # record.countdown_ready_to_ship = False + # else: + # if record.estimated_ready_ship_date: + # delta = record.estimated_ready_ship_date - waktu.now() + # 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 def _compute_lalamove_image_html(self): for record in self: diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml index 1832c31e..61ee2610 100644 --- a/indoteknik_custom/views/stock_picking.xml +++ b/indoteknik_custom/views/stock_picking.xml @@ -7,8 +7,8 @@ <field name="inherit_id" ref="stock.vpicktree"/> <field name="arch" type="xml"> <tree position="attributes"> - <attribute name="default_order">countdown_hours asc</attribute> -<!-- <attribute name="default_order">create_date desc</attribute>--> + <attribute name="default_order">final_seq asc</attribute> + <!-- <attribute name="default_order">create_date desc</attribute> --> </tree> <field name="json_popover" position="after"> <field name="date_done" optional="hide"/> @@ -18,7 +18,9 @@ <field name="note_logistic" optional="hide"/> <field name="note" optional="hide"/> <field name="date_reserved" optional="hide"/> + <field name="execution_date" optional="hide"/> <field name="state_reserve" optional="hide"/> + <field name="final_seq"/> <field name="countdown_hours" optional="hide"/> <field name="countdown_ready_to_ship" /> </field> |
