diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2026-01-15 00:46:47 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2026-01-15 00:46:47 +0700 |
| commit | b19788761f065be6593698d07f1e4743e151a8c6 (patch) | |
| tree | c3a113cfda68e5ec56431530e6a748ca62ae2151 | |
| parent | 2e1e5b798cc5b859a0c10cbdb4e48cbbe0687112 (diff) | |
<Miqdad> add done date & code improvement
| -rw-r--r-- | indoteknik_custom/models/gudang_service.py | 44 | ||||
| -rw-r--r-- | indoteknik_custom/views/gudang_service.xml | 14 |
2 files changed, 42 insertions, 16 deletions
diff --git a/indoteknik_custom/models/gudang_service.py b/indoteknik_custom/models/gudang_service.py index 585563ca..2fe239ad 100644 --- a/indoteknik_custom/models/gudang_service.py +++ b/indoteknik_custom/models/gudang_service.py @@ -9,12 +9,14 @@ class GudangService(models.Model): _name = "gudang.service" _description = "Gudang Service" _inherit = ['mail.thread', 'mail.activity.mixin'] + _order = 'remaining_date desc, id asc' name = fields.Char('Name', readonly=True) partner_id = fields.Many2one('res.partner', string='Customer', readonly=True) origin = fields.Many2one('sale.order', string='Origin SO', required=True) # picking_id = fields.Many2one('stock.picking', string = 'Picking ID', domain="[('sale_id', '=', origin)]") date = fields.Datetime('Date', default=fields.Datetime.now, required=True) + done_date = fields.Datetime(string='Date Done', copy=False) gudang_service_lines = fields.One2many('gudang.service.line', 'gudang_service_id', string='Gudang Service Lines') remaining_date = fields.Char('Remaining Date', compute='_compute_remaining_date') state = fields.Selection([('draft', 'Draft'), ('onprogress', 'On Progress'),('done', 'Done'), ('cancel', 'Cancel')], default='draft') @@ -71,38 +73,52 @@ class GudangService(models.Model): records._send_logistic_notification() - @api.depends('date', 'state') + @api.depends('date', 'state', 'done_date') def _compute_remaining_date(self): today = fields.Date.today() for rec in self: - if rec.state in ['done', 'cancel', 'draft'] or not rec.date: + if not rec.date: rec.remaining_date = 0 continue + + if rec.state in ['draft', 'cancel']: + rec.remaining_date = 0 + continue + + if rec.state == 'done' and rec.done_date: + rec.remaining_date = (rec.done_date.date() - rec.date.date()).days + continue + rec.remaining_date = (today - rec.date.date()).days + def action_submit(self): - self.state = 'onprogress' + for rec in self: + rec.state = 'onprogress' + rec.date = fields.Datetime.now() self._send_logistic_notification - # self.send_odoo_notification() def action_done(self): - self.state = 'done' - # self.send_odoo_notification() + for rec in self: + rec.state = 'done' + if not rec.done_date: + rec.done_date = fields.Datetime.now() def action_draft(self): """Reset to draft state""" - for record in self: - if record.state == 'cancel': - record.write({'state': 'draft'}) + for rec in self: + if rec.state == 'cancel': + rec.write({'state': 'draft'}) else: raise UserError("Only Canceled Record Can Be Reset To Draft") def action_cancel(self): - if self.state == 'done': - raise UserError("You cannot cancel a done record") - if not self.cancel_reason: - raise UserError("Cancel Reason must be filled") - self.state = 'cancel' + for rec in self: + if rec.state == 'done': + raise UserError("You cannot cancel a done record") + if not rec.cancel_reason: + raise UserError("Cancel Reason must be filled") + rec.state = 'cancel' # def write(vals, self): # self.send_odoo_notification() diff --git a/indoteknik_custom/views/gudang_service.xml b/indoteknik_custom/views/gudang_service.xml index 4365ba5d..a4150452 100644 --- a/indoteknik_custom/views/gudang_service.xml +++ b/indoteknik_custom/views/gudang_service.xml @@ -6,10 +6,19 @@ <field name="name">gudang.serivice.tree</field> <field name="model">gudang.service</field> <field name="arch" type="xml"> - <tree string="Monitoring Gudang Service" decoration-info="state == 'draft'" decoration-warning="state == 'onprogress'" decoration-success="state == 'done'" decoration-muted="state == 'cancel'"> + <!-- <tree string="Monitoring Gudang Service" + decoration-info="state == 'draft'" decoration-warning="state == 'onprogress'" + decoration-success="state == 'done'" decoration-muted="state == 'cancel'" + decoration-bf="remaining_date > 7" + > --> + <tree string="Monitoring Gudang Service" + decoration-info="state == 'draft'" decoration-warning="state == 'onprogress'" + decoration-success="state == 'done'" decoration-muted="state == 'cancel'" + > <field name="name"/> <field name="partner_id"/> <field name="origin"/> + <field name="date"/> <field name="remaining_date"/> <field name="state" widget="badge" decoration-info="state in ('draft')" decoration-warning="state == 'onprogress'" decoration-success="state == 'done'" decoration-muted="state == 'cancel'" /> @@ -50,6 +59,7 @@ <!-- <field name="picking_id"/> --> <field name="date"/> <field name="remaining_date"/> + <field name="done_date" attrs="{'invisible': [('state', 'not in', ['done'])]}"/> <field name="create_uid"/> <field name="cancel_reason" attrs="{'invisible': [('state', 'in', ['done', 'draft'])]}"/> @@ -59,7 +69,7 @@ <field name="gudang_service_lines"> <tree string="Product Lines" editable="top" create="0" delete="1"> <field name="product_id"/> - <field name="quantity"/> + <!-- <field name="quantity"/> --> <!-- <field name="picking_id"/> --> </tree> </field> |
