Untitled
unknown
plain_text
a year ago
1.3 kB
10
Indexable
class SaleOrder(models.Model):
_inherit = 'stock.picking'
@api.model
def cron_cancel_old_sp_booking(self):
#ambil tanggal hari ini
today_str = fields.Date.context_today(self)
#tgl hari ini diconvert ke string
today = fields.Date.from_string(today_str)
#cari settingan berapa hari di unreserved nya , kebetulan kolom di taroh di modul company
companies = self.env['res.company'].search([('days_to_cancel', '>', 0)])
for company in companies:
#variabel untuk menghitung hari ini dikurang berapa hari, contoh hari ini 23 agustus 2024 - 7 maka hasilnya = 16 agustus 2024
date2cancel = today - timedelta(days=company.days_to_cancel)
#hasil nya di convert ke string
date2cancel_str = fields.Date.to_string(date2cancel)
#cari stok picking dengan kriteria status nya assigned dan tanggal dibuat kurang dari sama dengan 16 agustus 2024
sp_quotations = self.env['stock.picking'].search([('state', '=', 'assigned'),('date', '<=', date2cancel_str)])
for sp_quotation in sp_quotations:
#jalankan action do unreserve di modul stok picking
sp_quotation.do_unreserve()
Editor is loading...
Leave a Comment