Skip to content

Commit

Permalink
Merge pull request #22 from brian10048/12.0-imp-fieldservice_sale
Browse files Browse the repository at this point in the history
[IMP] Fieldservice : raising a Validation Error if the sale order FSM location is empty and any sale order lines are set to any of the field service tracking options
  • Loading branch information
Bhavesh Odedra authored Dec 31, 2019
2 parents aaf6774 + 607a881 commit 7c50d91
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions fieldservice_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _
from odoo.exceptions import ValidationError


class SaleOrder(models.Model):
Expand Down Expand Up @@ -122,14 +123,17 @@ def _field_find_fsm_order(self):
def _action_confirm(self):
""" On SO confirmation, some lines generate field service orders. """
result = super(SaleOrder, self)._action_confirm()
self.order_line._field_service_generation()
if any(sol.product_id.field_service_tracking != 'no'
for sol in self):
if not self.fsm_location_id:
raise ValidationError(_("FSM Location must be set"))
self.order_line._field_service_generation()
return result

@api.multi
def action_invoice_create(self, grouped=False, final=False):
invoice_ids = super().action_invoice_create(grouped, final)
result = []
result.append(invoice_ids)
result = invoice_ids or []

for invoice_id in invoice_ids:
invoice = self.env['account.invoice'].browse(invoice_id)
Expand Down
2 changes: 1 addition & 1 deletion fieldservice_sale/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _field_create_fsm_order_prepare_values(self):
return {
'customer_id': self.order_id.partner_id.id,
'location_id': self.order_id.fsm_location_id.id,
'location_directions': self.fsm_location_id.direction,
'location_directions': self.order_id.fsm_location_id.direction,
'request_early': self.order_id.expected_date,
'scheduled_date_start': self.order_id.expected_date,
'description': self.name,
Expand Down

0 comments on commit 7c50d91

Please sign in to comment.