bemade_fsm: added many2many relationship to equipment from sale order lines. Set up summary and default equipment_ids from sale order. Ref #71.
This commit is contained in:
parent
8233f678cf
commit
5bb1023847
3 changed files with 79 additions and 22 deletions
|
|
@ -21,9 +21,19 @@ class FSMVisit(models.Model):
|
||||||
related="so_section_id.is_fully_delivered")
|
related="so_section_id.is_fully_delivered")
|
||||||
is_invoiced = fields.Boolean(string="Invoiced",
|
is_invoiced = fields.Boolean(string="Invoiced",
|
||||||
related="so_section_id.is_fully_delivered_and_invoiced")
|
related="so_section_id.is_fully_delivered_and_invoiced")
|
||||||
|
summarized_equipment_ids = fields.Many2many(comodel_name="bemade_fsm.equipment",
|
||||||
|
string="Equipment to Service",
|
||||||
|
compute="_compute_summarized_equipment_ids")
|
||||||
|
|
||||||
def _compute_is_invoiced(self):
|
@api.depends('so_section_id', 'sale_order_id.summary_equipment_ids')
|
||||||
self.is_invoiced = False
|
def _compute_summarized_equipment_ids(self):
|
||||||
|
for rec in self:
|
||||||
|
lines = rec.so_section_id.get_section_lines()
|
||||||
|
equipment_ids = []
|
||||||
|
for line in lines:
|
||||||
|
for equipment in line.equipment_ids:
|
||||||
|
equipment_ids.append(equipment)
|
||||||
|
rec.summarized_equipment_ids = equipment_ids
|
||||||
|
|
||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, vals_list):
|
def create(self, vals_list):
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,18 @@ from odoo.exceptions import ValidationError
|
||||||
class SaleOrder(models.Model):
|
class SaleOrder(models.Model):
|
||||||
_inherit = 'sale.order'
|
_inherit = 'sale.order'
|
||||||
|
|
||||||
equipment_id = fields.Many2one(comodel_name="bemade_fsm.equipment",
|
valid_equipment_ids = fields.One2many(comodel_name="bemade_fsm.equipment",
|
||||||
string="Equipment to Service",
|
related="partner_id.owned_equipment_ids")
|
||||||
tracking=True,
|
default_equipment_ids = fields.Many2many(comodel_name="bemade_fsm.equipment",
|
||||||
compute="_compute_equipment",
|
string="Default Equipment to Service",
|
||||||
inverse="_inverse_equipment",
|
help="The default equipment to service for new sale order lines.",
|
||||||
store=True)
|
compute="_compute_default_equipment",
|
||||||
|
inverse="_inverse_default_equipment",
|
||||||
|
store=True, )
|
||||||
|
|
||||||
|
summary_equipment_ids = fields.Many2many(comodel_name="bemade_fsm.equipment",
|
||||||
|
string="Equipment Being Serviced",
|
||||||
|
compute="_compute_summary_equipment_ids")
|
||||||
|
|
||||||
site_contacts = fields.Many2many(comodel_name='res.partner',
|
site_contacts = fields.Many2many(comodel_name='res.partner',
|
||||||
relation="sale_order_site_contacts_rel",
|
relation="sale_order_site_contacts_rel",
|
||||||
|
|
@ -29,10 +35,15 @@ class SaleOrder(models.Model):
|
||||||
inverse_name="sale_order_id",
|
inverse_name="sale_order_id",
|
||||||
readonly=False)
|
readonly=False)
|
||||||
|
|
||||||
|
@api.depends('order_line.equipment_ids')
|
||||||
|
def _compute_summary_equipment_ids(self):
|
||||||
|
for rec in self:
|
||||||
|
rec.summary_equipment_ids = rec.order_line.mapped('equipment_ids')
|
||||||
|
|
||||||
@api.onchange('partner_shipping_id')
|
@api.onchange('partner_shipping_id')
|
||||||
def _onchange_partner_shipping_id(self):
|
def _onchange_partner_shipping_id(self):
|
||||||
super()._onchange_partner_shipping_id()
|
super()._onchange_partner_shipping_id()
|
||||||
self._compute_equipment()
|
self._compute_default_equipment()
|
||||||
self._compute_default_contacts()
|
self._compute_default_contacts()
|
||||||
|
|
||||||
@api.depends('partner_shipping_id')
|
@api.depends('partner_shipping_id')
|
||||||
|
|
@ -45,18 +56,19 @@ class SaleOrder(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@api.depends('partner_shipping_id')
|
@api.depends('partner_shipping_id')
|
||||||
def _compute_equipment(self):
|
def _compute_default_equipment(self):
|
||||||
|
ids = self.partner_shipping_id.equipment_ids
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.equipment_id = self.partner_shipping_id.equipment_ids if len(
|
rec.default_equipment_ids = ids if len(ids) < 4 else False
|
||||||
self.partner_shipping_id.equipment_ids) <= 1 else False
|
|
||||||
|
|
||||||
def _inverse_equipment(self):
|
def _inverse_default_equipment(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SaleOrderLine(models.Model):
|
class SaleOrderLine(models.Model):
|
||||||
_inherit = 'sale.order.line'
|
_inherit = 'sale.order.line'
|
||||||
|
valid_equipment_ids = fields.One2many(comodel_name="bemade_fsm.equipment",
|
||||||
|
related="order_id.partner_id.owned_equipment_ids")
|
||||||
visit_id = fields.One2many(comodel_name="bemade_fsm.visit",
|
visit_id = fields.One2many(comodel_name="bemade_fsm.visit",
|
||||||
inverse_name="so_section_id",
|
inverse_name="so_section_id",
|
||||||
string="Visit")
|
string="Visit")
|
||||||
|
|
@ -65,9 +77,14 @@ class SaleOrderLine(models.Model):
|
||||||
help="Indicates whether a line or all the lines in a section have been"
|
help="Indicates whether a line or all the lines in a section have been"
|
||||||
"entirely delivered.")
|
"entirely delivered.")
|
||||||
is_fully_delivered_and_invoiced = fields.Boolean(string="Fully Invoiced",
|
is_fully_delivered_and_invoiced = fields.Boolean(string="Fully Invoiced",
|
||||||
compute="_compute_is_fully_invoiced",
|
compute="_compute_is_fully_invoiced",
|
||||||
help="Indicates whether a line or all the lines in a section have been"
|
help="Indicates whether a line or all the lines in a section have been"
|
||||||
"entirely delivered and invoiced.")
|
"entirely delivered and invoiced.")
|
||||||
|
equipment_ids = fields.Many2many(string="Equipment to Service",
|
||||||
|
comodel_name="bemade_fsm.equipment",
|
||||||
|
relation="bemade_fsm_equipment_sale_order_line_rel",
|
||||||
|
column1="sale_order_line_id",
|
||||||
|
column2="equipment_id")
|
||||||
|
|
||||||
def _timesheet_create_task(self, project):
|
def _timesheet_create_task(self, project):
|
||||||
""" Generate task for the given so line, and link it.
|
""" Generate task for the given so line, and link it.
|
||||||
|
|
@ -129,8 +146,8 @@ class SaleOrderLine(models.Model):
|
||||||
"This task has been created from: <a href=# data-oe-model=sale.order data-oe-id=%d>%s</a> (%s)") % (
|
"This task has been created from: <a href=# data-oe-model=sale.order data-oe-id=%d>%s</a> (%s)") % (
|
||||||
self.order_id.id, self.order_id.name, self.product_id.name)
|
self.order_id.id, self.order_id.name, self.product_id.name)
|
||||||
task.message_post(body=task_msg)
|
task.message_post(body=task_msg)
|
||||||
if not task.equipment_ids and self.order_id.equipment_id:
|
if not task.equipment_ids and self.equipment_ids:
|
||||||
task.write({'equipment_ids': [Command.set([self.order_id.equipment_id.id])]})
|
task.write({'equipment_ids': [Command.set([self.equipment_ids.ids])]})
|
||||||
task.name = _generate_task_name(tmpl)
|
task.name = _generate_task_name(tmpl)
|
||||||
return task
|
return task
|
||||||
|
|
||||||
|
|
@ -146,6 +163,24 @@ class SaleOrderLine(models.Model):
|
||||||
return
|
return
|
||||||
self.is_fully_delivered_and_invoiced = self._iterate_items_compute_bool(lambda l: l.qty_to_invoice == 0)
|
self.is_fully_delivered_and_invoiced = self._iterate_items_compute_bool(lambda l: l.qty_to_invoice == 0)
|
||||||
|
|
||||||
|
def get_section_lines(self):
|
||||||
|
""" Returns a list containing the sale order lines that fall under this section. """
|
||||||
|
self.ensure_one()
|
||||||
|
assert self.display_type == 'line_section', 'Method called incorrectly on non-section order line.'
|
||||||
|
found = False
|
||||||
|
lines = []
|
||||||
|
for line in self.order_id:
|
||||||
|
if line == self:
|
||||||
|
found = True
|
||||||
|
continue
|
||||||
|
if not found:
|
||||||
|
continue
|
||||||
|
if line.display_type == 'line_section': # Stop when we hit the next section
|
||||||
|
return lines
|
||||||
|
else:
|
||||||
|
lines.add(line)
|
||||||
|
return lines
|
||||||
|
|
||||||
def _iterate_items_compute_bool(self, single_line_func):
|
def _iterate_items_compute_bool(self, single_line_func):
|
||||||
if not self.display_type:
|
if not self.display_type:
|
||||||
return single_line_func(self)
|
return single_line_func(self)
|
||||||
|
|
|
||||||
|
|
@ -13,16 +13,28 @@
|
||||||
context="{'tree_view_ref': 'bemade_fsm.bemade_fsm_visit_tree'}"/>
|
context="{'tree_view_ref': 'bemade_fsm.bemade_fsm_visit_tree'}"/>
|
||||||
</group>
|
</group>
|
||||||
<group name="field_service_info" string="Contacts and Equipment">
|
<group name="field_service_info" string="Contacts and Equipment">
|
||||||
<field name="equipment_id"
|
<field name="valid_equipment_ids" invisible="1"/>
|
||||||
domain="[('partner_location_id', '=', partner_shipping_id)]"
|
<field name="summary_equipment_ids"
|
||||||
context="{'default_partner_location_id': partner_shipping_id,}"/>
|
context="{'default_partner_location_id': partner_shipping_id,}"
|
||||||
|
widget="many2many_tags"/>
|
||||||
<field name="site_contacts"
|
<field name="site_contacts"
|
||||||
context="{'tree_view_ref': 'bemade_fsm.fsm_contacts_view_tree'}"/>
|
context="{'tree_view_ref': 'bemade_fsm.fsm_contacts_view_tree'}"/>
|
||||||
<field name="work_order_contacts"
|
<field name="work_order_contacts"
|
||||||
context="{'tree_view_ref': 'bemade_fsm.fsm_contacts_view_tree'}"/>
|
context="{'tree_view_ref': 'bemade_fsm.fsm_contacts_view_tree'}"/>
|
||||||
|
|
||||||
|
<field name="default_equipment_ids"
|
||||||
|
context="{'default_partner_location_id': partner_shipping_id,}"
|
||||||
|
widget="many2many_tags"
|
||||||
|
domain="[('id', 'in', valid_equipment_ids)]"/>
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
<xpath expr="//tree//field[@name='name']" position="after">
|
||||||
|
<field name="valid_equipment_ids" invisible="1"/>
|
||||||
|
<field name="equipment_ids"
|
||||||
|
widget="many2many_tags"
|
||||||
|
domain="[('id', 'in', valid_equipment_ids)]"/>
|
||||||
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
<record id="bemade_fsm_visit_tree" model="ir.ui.view">
|
<record id="bemade_fsm_visit_tree" model="ir.ui.view">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue