bemade_fsm: added is_complete to tasks for easier PDF generation.

This commit is contained in:
Marc Durepos 2023-07-31 15:51:13 -04:00
parent b787f81325
commit 70d8893178
3 changed files with 103 additions and 33 deletions

View file

@ -34,6 +34,7 @@
'sale_project',
'sale_stock',
'sale_planning',
'worksheet',
'industry_fsm_stock',
'industry_fsm_report',
'bemade_partner_root_ancestor',

View file

@ -49,6 +49,8 @@ class Task(models.Model):
visit_id = fields.Many2one(comodel_name='bemade_fsm.visit')
is_complete = fields.Boolean(compute="_compute_is_complete")
# user_id = fields.Many2one('res.users', compute='_compute_user_id')
#
# @api.depends('user_ids')
@ -56,6 +58,26 @@ class Task(models.Model):
# for rec in self:
# rec.user_id = rec.user_ids and rec.user_ids[0] or 0
def _get_closed_stage_by_project(self):
""" Gets the stage representing completed tasks for each project in
self.project_id. Copied from industry_fsm/.../project.py:217-221
for consistency.
:returns: Dict of project.project -> project.task.type"""
return {
project:
project.type_ids.filtered(lambda stage: stage.is_closed)[:1]
or project.type_ids[-1:]
for project in self.project_id
}
@api.depends('project_id', 'stage_id.is_closed')
def _compute_is_complete(self):
closing_stages = self._get_closed_stage_by_project()
for rec in self:
rec.is_complete = rec.stage_id == (rec.project_id
and closing_stages[rec.project_id])
def _get_related_planning_slots(self):
domain = expression.AND([
self._get_domain_compute_forecast_hours(),

View file

@ -7,7 +7,7 @@
<field name="report_type">qweb-pdf</field>
<field name="report_name">bemade_fsm.worksheet_complete</field>
<field name="print_report_name">
'%s Worksheet %s' % (time.now().strftime('%Y-%m-%d'),object.name)
'%s Worksheet %s' % (time.strftime('%Y-%m-%d'), object.name)
</field>
<field name="binding_model_id" ref="model_project_task"/>
<field name="binding_type">report</field>
@ -25,15 +25,15 @@
</template>
<template id="worksheet_complete_page">
<t t-set="address">
<t t-set="address" t-if="doc.sale_order_id">
<strong class="big-red">Customer:</strong>
<div t-field="doc.partner_id"
<div t-field="doc.sale_order_id.partner_id"
t-options='{"widget": "contact",
"fields": ["address", "name"], "no_marker": True}'/>
</t>
<t t-set="information_block">
<strong>Service Address:</strong>
<div t-field="doc.customer_shipping_id"
<div t-field="doc.partner_id"
t-options='{"widget": "contact",
"fields": ["address", "name", "phone"],
"no_marker": True, "phone_icons": True}'/>
@ -46,41 +46,88 @@
</h2>
<div class="container wo-information">
<div t-if="doc.sale_order_id.client_order_ref" class="col-3">
<p class="m-0">
<strong>Your Reference: </strong>
<span t-field="doc.sale_order_id.client_order_ref"/>
</p>
<p t-if="doc.planned_date_begin" class="m-0">
<strong t-if="doc.planned_date_begin" >Planned for: </strong>
<span t-field="doc.planned_date_begin"
t-options='{"widget": "datetime"}'/>
</p>
</div>
<div class="col-3">
<strong>Technician(s):</strong>
<t t-foreach="doc.technician_ids" t-as="technician"
t-if="doc.technician_ids">
<p class="m-0" t-field="technician.name"/>
</t>
</div>
<div class="col-3">
<strong>Site Contacts:</strong>
<t t-foreach="doc.site_contacts" t-as="contact">
<p class="m-0" t-out="contact"
t-options='{"widget": "contact",
<div class="row mt32 mb32" id="informations">
<div t-if="doc.sale_order_id.client_order_ref" class="col-3">
<p class="m-0">
<strong>Your Reference: </strong>
<span t-field="doc.sale_order_id.client_order_ref"/>
</p>
<p t-if="doc.planned_date_begin" class="m-0">
<strong t-if="doc.planned_date_begin">Planned
for: </strong>
<span t-field="doc.planned_date_begin"
t-options='{"widget": "datetime"}'/>
</p>
</div>
<div class="col-3">
<strong>Technician(s):</strong>
<t t-foreach="doc.user_ids" t-as="technician"
t-if="doc.user_ids">
<p class="m-0" t-field="technician.name"/>
</t>
</div>
<div class="col-3">
<strong>Site Contacts:</strong>
<t t-foreach="doc.site_contacts" t-as="contact">
<p class="m-0" t-out="contact"
t-options='{"widget": "contact",
"fields": ["name", "phone", "mobile", "email"],
"no_marker": True, "phone_icons": True}'/>
</t>
</t>
</div>
<div class="col-3">
<strong>Work order attn:</strong>
<t t-foreach="doc.work_order_contacts" t-as="contact">
<p class="m-0" t-out="contact"/>
</t>
</div>
</div>
<div class="col-3">
<strong>Work order attn:</strong>
<t t-foreach="doc.work_order_contacts" t-as="contact">
<p class="m-0" t-out="contact"/>
</t>
<div class="row">
<div class="col mb16">
<h3 class="mb32"><strong>Interventions</strong></h3>
</div>
</div>
<t t-foreach="doc.child_ids" t-as="intervention">
<div class="container wo-intervention mb16">
<div class="row mb16 pb16">
<div class="col-12 mb16 tb16">
<h4><strong>
<span t-field="intervention.name"/>
(<span t-field="intervention.equipment_ids"
t-options="{'widget': 'many2many_tags'}"/>
)
</strong></h4>
<p class="mb16" t-field="intervention.description"/>
</div>
</div>
<table class="table table-borderless">
<thead>
<th>Done</th>
<th>Task to do</th>
</thead>
<tbody>
<t t-foreach="intervention.child_ids" t-as="task">
<tr class="wo-task">
<td style="width: 5%">
<input type="checkbox"
t-att-checked="task.is_complete"/>
</td>
<td style="width: 95%">
<p t-field="task.name"/>
<p t-field="task.description"/>
</td>
<!-- TODO: Figure out what to do with the old
concept of task comments -->
</tr>
</t>
</tbody>
</table>
</div>
</t>
</div>
</div>
</template>
</data>
</odoo>