From 7230d53964658a66841eace12cef0de76b72a96e Mon Sep 17 00:00:00 2001 From: snd Date: Fri, 30 Jun 2023 15:09:23 +0200 Subject: [PATCH] [IMP] repair: smarter smart buttons Added a todo count field on the button where the lot is the product being repaired. Changed the texts to better fit the buttons. Part-of: odoo/odoo#129933 --- addons/repair/models/stock_lot.py | 13 ++++++++++-- addons/repair/views/stock_lot_views.xml | 27 ++++++++++++++++--------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/addons/repair/models/stock_lot.py b/addons/repair/models/stock_lot.py index 0255d909f50..890d978a013 100644 --- a/addons/repair/models/stock_lot.py +++ b/addons/repair/models/stock_lot.py @@ -9,6 +9,7 @@ class StockLot(models.Model): repair_order_ids = fields.Many2many('repair.order', string="Repair Orders", compute="_compute_repair_order_ids") repair_order_count = fields.Integer('Repair order count', compute="_compute_repair_order_ids") + in_repair_count = fields.Integer('In repair count', compute="_compute_in_repair_count") repaired_count = fields.Integer('Repaired count', compute='_compute_repaired_count') @api.depends('name') @@ -21,9 +22,17 @@ class StockLot(models.Model): lot.repair_order_ids = repair_orders[lot.id] lot.repair_order_count = len(lot.repair_order_ids) - def _compute_repaired_count(self): + def _compute_in_repair_count(self): + lot_data = self.env['repair.order']._read_group([('lot_id', 'in', self.ids), ('state', 'not in', ('done', 'cancel'))], ['lot_id'], ['__count']) + result = {lot.id: count for lot, count in lot_data} for lot in self: - lot.repaired_count = len(self.env['repair.order'].search([('lot_id', '=', self.id), ('state', '=', 'done')])) + lot.in_repair_count = result.get(lot.id, 0) + + def _compute_repaired_count(self): + lot_data = self.env['repair.order']._read_group([('lot_id', 'in', self.ids), ('state', '=', 'done')], ['lot_id'], ['__count']) + result = {lot.id: count for lot, count in lot_data} + for lot in self: + lot.repaired_count = result.get(lot.id, 0) def action_lot_open_repairs(self): action = self.env["ir.actions.actions"]._for_xml_id("repair.action_repair_order_tree") diff --git a/addons/repair/views/stock_lot_views.xml b/addons/repair/views/stock_lot_views.xml index c2aeff9e581..36f7aad4c79 100644 --- a/addons/repair/views/stock_lot_views.xml +++ b/addons/repair/views/stock_lot_views.xml @@ -9,19 +9,28 @@