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 28a9e7a8d1
commit 4c7ba22f87
3 changed files with 103 additions and 33 deletions

View file

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

View file

@ -49,6 +49,8 @@ class Task(models.Model):
visit_id = fields.Many2one(comodel_name='bemade_fsm.visit') 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') # user_id = fields.Many2one('res.users', compute='_compute_user_id')
# #
# @api.depends('user_ids') # @api.depends('user_ids')
@ -56,6 +58,26 @@ class Task(models.Model):
# for rec in self: # for rec in self:
# rec.user_id = rec.user_ids and rec.user_ids[0] or 0 # 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): def _get_related_planning_slots(self):
domain = expression.AND([ domain = expression.AND([
self._get_domain_compute_forecast_hours(), self._get_domain_compute_forecast_hours(),

View file

@ -7,7 +7,7 @@
<field name="report_type">qweb-pdf</field> <field name="report_type">qweb-pdf</field>
<field name="report_name">bemade_fsm.worksheet_complete</field> <field name="report_name">bemade_fsm.worksheet_complete</field>
<field name="print_report_name"> <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>
<field name="binding_model_id" ref="model_project_task"/> <field name="binding_model_id" ref="model_project_task"/>
<field name="binding_type">report</field> <field name="binding_type">report</field>
@ -25,15 +25,15 @@
</template> </template>
<template id="worksheet_complete_page"> <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> <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", t-options='{"widget": "contact",
"fields": ["address", "name"], "no_marker": True}'/> "fields": ["address", "name"], "no_marker": True}'/>
</t> </t>
<t t-set="information_block"> <t t-set="information_block">
<strong>Service Address:</strong> <strong>Service Address:</strong>
<div t-field="doc.customer_shipping_id" <div t-field="doc.partner_id"
t-options='{"widget": "contact", t-options='{"widget": "contact",
"fields": ["address", "name", "phone"], "fields": ["address", "name", "phone"],
"no_marker": True, "phone_icons": True}'/> "no_marker": True, "phone_icons": True}'/>
@ -46,41 +46,88 @@
</h2> </h2>
<div class="container wo-information"> <div class="container wo-information">
<div t-if="doc.sale_order_id.client_order_ref" class="col-3"> <div class="row mt32 mb32" id="informations">
<p class="m-0"> <div t-if="doc.sale_order_id.client_order_ref" class="col-3">
<strong>Your Reference: </strong> <p class="m-0">
<span t-field="doc.sale_order_id.client_order_ref"/> <strong>Your Reference: </strong>
</p> <span t-field="doc.sale_order_id.client_order_ref"/>
<p t-if="doc.planned_date_begin" class="m-0"> </p>
<strong t-if="doc.planned_date_begin" >Planned for: </strong> <p t-if="doc.planned_date_begin" class="m-0">
<span t-field="doc.planned_date_begin" <strong t-if="doc.planned_date_begin">Planned
t-options='{"widget": "datetime"}'/> for: </strong>
</p> <span t-field="doc.planned_date_begin"
</div> t-options='{"widget": "datetime"}'/>
<div class="col-3"> </p>
<strong>Technician(s):</strong> </div>
<t t-foreach="doc.technician_ids" t-as="technician" <div class="col-3">
t-if="doc.technician_ids"> <strong>Technician(s):</strong>
<p class="m-0" t-field="technician.name"/> <t t-foreach="doc.user_ids" t-as="technician"
</t> t-if="doc.user_ids">
</div> <p class="m-0" t-field="technician.name"/>
<div class="col-3"> </t>
<strong>Site Contacts:</strong> </div>
<t t-foreach="doc.site_contacts" t-as="contact"> <div class="col-3">
<p class="m-0" t-out="contact" <strong>Site Contacts:</strong>
t-options='{"widget": "contact", <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"], "fields": ["name", "phone", "mobile", "email"],
"no_marker": True, "phone_icons": True}'/> "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>
<div class="col-3"> <div class="row">
<strong>Work order attn:</strong> <div class="col mb16">
<t t-foreach="doc.work_order_contacts" t-as="contact"> <h3 class="mb32"><strong>Interventions</strong></h3>
<p class="m-0" t-out="contact"/> </div>
</t>
</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>
</div> </div>
</template> </template>
</data> </data>
</odoo> </odoo>