hr_timesheet_sheet* fixes: back to list after remove a timesheet. bulk unfreeze confirmed and pending sheets
This commit is contained in:
parent
8b0d0bb6cc
commit
0323b6672e
11 changed files with 354 additions and 34 deletions
|
|
@ -10,6 +10,10 @@ class HrTimesheetSheetUnfreezeWizard(models.TransientModel):
|
|||
_name = "hr_timesheet.sheet.unfreeze.wizard"
|
||||
_description = "Unfreeze Pending Timesheet Sheets"
|
||||
|
||||
sheet_ids = fields.Many2many(
|
||||
comodel_name="hr_timesheet.sheet",
|
||||
string="Frozen Sheets To Release",
|
||||
)
|
||||
sheet_count = fields.Integer(
|
||||
string="Frozen Sheets",
|
||||
compute="_compute_frozen_data",
|
||||
|
|
@ -27,21 +31,36 @@ class HrTimesheetSheetUnfreezeWizard(models.TransientModel):
|
|||
compute="_compute_summary_html",
|
||||
)
|
||||
|
||||
# No @api.depends: the figures come from the state of the whole database,
|
||||
# not from any field of the wizard. The wizard is created anew every time
|
||||
# the action is opened, so they are computed once, when the dialog is read.
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super().default_get(fields_list)
|
||||
if "sheet_ids" in fields_list:
|
||||
sheet_model = self.env["hr_timesheet.sheet"]
|
||||
sheets = sheet_model.search(sheet_model._unfreeze_domain())
|
||||
res["sheet_ids"] = [fields.Command.set(sheets.ids)]
|
||||
return res
|
||||
|
||||
@api.depends("sheet_ids")
|
||||
def _compute_frozen_data(self):
|
||||
sheet_model = self.env["hr_timesheet.sheet"]
|
||||
sheets = sheet_model.search(sheet_model._unfreeze_domain())
|
||||
groups = self.env["account.analytic.line"].read_group(
|
||||
[("sheet_id", "in", sheets.ids)], ["unit_amount"], []
|
||||
)
|
||||
timesheet_count = groups[0]["__count"] if groups else 0
|
||||
timesheet_hours = (groups[0]["unit_amount"] if groups else 0.0) or 0.0
|
||||
"""The figures describe ``sheet_ids``, not the database.
|
||||
|
||||
Depending on a real field is what makes the figures appear in the
|
||||
interface: opening an action on a transient model builds the record
|
||||
with ``default_get()`` + ``onchange()``, and that flow seeds every
|
||||
field of the view into the cache before computing anything. A compute
|
||||
with no dependency is then a cache hit on the default value, and the
|
||||
dialog reports zero.
|
||||
"""
|
||||
line_model = self.env["account.analytic.line"]
|
||||
for wizard in self:
|
||||
sheets = wizard.sheet_ids
|
||||
groups = line_model.read_group(
|
||||
[("sheet_id", "in", sheets.ids)], ["unit_amount"], []
|
||||
)
|
||||
group = groups[0] if groups else {}
|
||||
wizard.sheet_count = len(sheets)
|
||||
wizard.timesheet_count = timesheet_count
|
||||
wizard.timesheet_hours = timesheet_hours
|
||||
wizard.timesheet_count = group.get("__count") or 0
|
||||
wizard.timesheet_hours = group.get("unit_amount") or 0.0
|
||||
|
||||
@api.depends("sheet_count", "timesheet_count", "timesheet_hours")
|
||||
def _compute_summary_html(self):
|
||||
|
|
@ -61,7 +80,7 @@ class HrTimesheetSheetUnfreezeWizard(models.TransientModel):
|
|||
|
||||
def action_unfreeze(self):
|
||||
self.ensure_one()
|
||||
count = self.env["hr_timesheet.sheet"]._unfreeze_sheets()
|
||||
count = self.env["hr_timesheet.sheet"]._unfreeze_sheets(self.sheet_ids)
|
||||
if count:
|
||||
message = _("%s timesheet sheet(s) have been set back to draft.", count)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -9,6 +9,12 @@
|
|||
<field name="model">hr_timesheet.sheet.unfreeze.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Unfreeze Pending Sheets">
|
||||
<!--
|
||||
The figures depend on sheet_ids, and the onchange flow that
|
||||
builds the dialog only asks default_get() for the fields of
|
||||
the view. Drop this field and the dialog reports zero.
|
||||
-->
|
||||
<field name="sheet_ids" invisible="1" />
|
||||
<field name="summary_html" nolabel="1" readonly="1" />
|
||||
<group attrs="{'invisible': [('sheet_count', '=', 0)]}">
|
||||
<field name="sheet_count" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue