bemade_fsm: added work order number, significant mods to work order PDF.

This commit is contained in:
Marc Durepos 2023-08-22 21:32:58 -04:00
parent 838db389b0
commit 4a4214fabb
4 changed files with 72 additions and 21 deletions

View file

@ -2,6 +2,7 @@ from odoo import fields, models, api, Command, _
from odoo.exceptions import ValidationError, UserError
from odoo.osv import expression
from collections import defaultdict, namedtuple
import re
class Task(models.Model):
@ -53,12 +54,29 @@ class Task(models.Model):
store=False,
compute='_compute_relevant_order_lines', )
work_order_number = fields.Char(readonly=True)
@api.model_create_multi
def create(self, vals):
res = super().create(vals)
for rec in res:
if rec.sale_order_id:
seq = 1
prev_seqs = self.sale_order_id.tasks_ids and \
self.sale_order_id.tasks_ids.mapped('work_order_number')
if prev_seqs:
seq += max(map(lambda n: int(re.search("\d+$", n).start() or 0),
prev_seqs))
rec.work_order_number = rec.sale_order_id.name.replace('SO', 'WO', 1) \
+ f"-{seq}"
return res
@api.depends('sale_order_id')
def _compute_relevant_order_lines(self):
for rec in self:
rec.relevant_order_lines = (
rec.sale_order_id and rec.sale_order_id.get_relevant_order_lines(
rec) or False)
rec.sale_order_id and rec.sale_order_id.get_relevant_order_lines(
rec) or False)
def _get_closed_stage_by_project(self):
""" Gets the stage representing completed tasks for each project in
@ -160,7 +178,7 @@ class Task(models.Model):
""" Applies naming to the entire task tree for tasks that are part of this
recordset. Root tasks are named:
SOXXXXX: Partner Shipping Name - Sale Line Name (Template Name)
Partner Shipping Name - Sale Line Name (Template Name)
Child tasks with sale_line_id are named by their template if set, sale line name
if not.
@ -173,8 +191,7 @@ class Task(models.Model):
template = rec.sale_line_id and rec.sale_line_id.product_id.task_template_id
if not rec.parent_id:
rec.name = f"{rec.sale_order_id.name}: " \
f"{rec.sale_order_id.partner_shipping_id.name} - " \
rec.name = f"{rec.sale_order_id.partner_shipping_id.name} - " \
f"{rec.sale_line_id.name}"
if template:
rec.name += f" ({template.name})"

View file

@ -170,6 +170,9 @@
<span t-out="equipment_id.complete_name + (', ' if not equipment_id_last else '')"/>
</t>
</h3>
<div>
<span t-esc="intervention.description"/>
</div>
<t t-set="tasks" t-value="intervention.child_ids"/>
<div t-if="tasks" class="table-responsive-sm">
<table class="table table-sm o_main_table">
@ -183,7 +186,7 @@
</thead>
<tbody>
<t t-foreach="tasks" t-as="task">
<tr class="o_line_section">
<tr class="o_line_section p-1 m-1">
<td t-out="task.stage_id.name"/>
<td>
<span t-out="task.name"/>
@ -211,14 +214,15 @@
</template>
<template id="workorder_page_info_block">
<h1>Work Order <span t-out="doc.work_order_number"></span></h1>
<div class="row">
<div t-attf-class="{{'col-6' if report_type == 'pdf' else 'col-md-6 col-12'}}">
<div t-if="doc.user_ids"><strong>Technicians: </strong></div>
<div t-if="doc.user_ids"><h6>Technicians: </h6></div>
<t t-foreach="doc.user_ids" t-as="user">
<div class="mb-3">
<div t-esc="user" t-options='{
"widget": "contact",
"fields": ["name", "address", "phone", "email"]
"fields": ["name", "email"]
}'/>
</div>
</t>
@ -226,7 +230,7 @@
<div t-attf-class="{{('col-6' if report_type == 'pdf' else 'col-md-6 col-12') + ' mb-3'}}">
<t t-if="doc.partner_id">
<div><strong>Customer: </strong></div>
<div><h6>Customer: </h6></div>
<div t-esc="doc.partner_id" t-options='{
"widget": "contact",
"fields": ["name", "address",]
@ -234,6 +238,30 @@
</t>
</div>
</div>
<div class="row">
<div t-attf-class="{{'col-6' if report_type == 'pdf' else 'col-md-6 col-12'}}">
<div t-if="doc.site_contacts"><h6>Site Contacts: </h6></div>
<t t-foreach="doc.site_contacts" t-as="contact">
<div class="mb-3">
<div t-esc="contact" t-options='{
"widget": "contact",
"fields": ["name", "phone", "email"]
}'/>
</div>
</t>
</div>
<div t-attf-class="{{'col-6' if report_type == 'pdf' else 'col-md-6 col-12'}}">
<div t-if="doc.work_order_contacts"><h6>Work Order Contacts: </h6></div>
<t t-foreach="doc.work_order_contacts" t-as="contact">
<div class="mb-3">
<div t-esc="contact" t-options='{
"widget": "contact",
"fields": ["name", "phone", "email"]
}'/>
</div>
</t>
</div>
</div>
</template>
<template id="workorder_page_signature_block">
<div t-if="doc.worksheet_signature">

View file

@ -6,7 +6,7 @@
<field name="report_name">bemade_fsm.work_order</field>
<field name="report_file">bemade_fsm.work_order</field>
<field name="print_report_name">'%s Work Order %s' % (
time.strftime('%Y-%m-%d'), object.name)</field>
time.strftime('%Y-%m-%d'), object.work_order_number)</field>
<field name="report_type">qweb-pdf</field>
</record>
</data>

View file

@ -7,6 +7,12 @@
<field name="inherit_id" ref="industry_fsm.view_task_form2_inherit"/>
<field name="priority" eval="8"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']/.." position="before">
<h1 class="d-flex flex-row justify-content-between">
<field name="work_order_number"
attrs="{'invisible': [('work_order_number', '=', False)]}"/>
</h1>
</xpath>
<xpath expr="//page[@name='extra_info']" position="after">
<page string="Field Service" name="field_service">
<group name="equipment_and_contacts">
@ -89,17 +95,17 @@
('parent_id', '=', False)]
</field>
</record>
<!-- <record id="project_task_view_calendar_fsm" model="ir.ui.view">-->
<!-- <field name="name">bemade_fsm.project_task_view_calendar_fsm</field>-->
<!-- <field name="inherit_id" ref="industry_fsm.project_task_view_calendar_fsm"/>-->
<!-- <field name="model">project.task</field>-->
<!-- <field name="arch" type="xml">-->
<!-- <field name="user_ids" position="attributes">-->
<!-- <attribute name="filters">1</attribute>-->
<!-- <attribute name="color">user_ids</attribute>-->
<!-- </field>-->
<!-- </field>-->
<!-- </record>-->
<!-- <record id="project_task_view_calendar_fsm" model="ir.ui.view">-->
<!-- <field name="name">bemade_fsm.project_task_view_calendar_fsm</field>-->
<!-- <field name="inherit_id" ref="industry_fsm.project_task_view_calendar_fsm"/>-->
<!-- <field name="model">project.task</field>-->
<!-- <field name="arch" type="xml">-->
<!-- <field name="user_ids" position="attributes">-->
<!-- <attribute name="filters">1</attribute>-->
<!-- <attribute name="color">user_ids</attribute>-->
<!-- </field>-->
<!-- </field>-->
<!-- </record>-->
<record id="project_task_view_calendar_fsm_no_worksheet" model="ir.ui.view">
<field name="name">bemade_fsm.project_task_view_calendar_no_worksheet</field>
<field name="inherit_id"