Skip to content

Commit

Permalink
[IMP] fieldservice_account_analytic - setting the analytic account on…
Browse files Browse the repository at this point in the history
… a timesheet line in a method to inherit it
  • Loading branch information
baimont committed Jun 17, 2021
1 parent 4e45f3e commit dd05002
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions fieldservice_account_analytic/models/analytic_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ class AccountAnalyticLine(models.Model):
def create(self, vals):
order = self.env["fsm.order"].browse(vals.get("fsm_order_id"))
if order:
if order.location_id.analytic_account_id:
vals["account_id"] = order.location_id.analytic_account_id.id
else:
raise ValidationError(
_("No analytic account set " "on the order's Location.")
)
self._update_vals_with_account_id(order, vals)
return super(AccountAnalyticLine, self).create(vals)

def _update_vals_with_account_id(self, order, vals):
analytic_account = order.location_id.analytic_account_id
if analytic_account:
vals["account_id"] = analytic_account.id
else:
raise ValidationError(
_("No analytic account set on the order's Location.")
)

@api.onchange("product_id")
def onchange_product_id(self):
if self.product_id:
Expand Down

0 comments on commit dd05002

Please sign in to comment.