Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions fieldservice_account_analytic/models/analytic_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ class AccountAnalyticLine(models.Model):
fsm_order_id = fields.Many2one("fsm.order", string="FSM Order")
product_id = fields.Many2one("product.product", string="Time Type")

@api.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:
@api.constrains("fsm_order_id")
def _check_fsm_order_id(self):
for line in self:
if (
line.fsm_order_id
and not line.fsm_order_id.location_id.analytic_account_id
):
raise ValidationError(
_("No analytic account set " "on the order's Location.")
_(
"No analytic account set on the order's Location "
"%(location_name)s. Please set an analytic account on the "
"Location before creating an analytic line for this order.",
location_name=line.fsm_order_id.location_id.name,
)
)
return super().create(vals)

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