diff --git a/fieldservice_account_analytic/data/ir_rule.xml b/fieldservice_account_analytic/data/ir_rule.xml index 279666bf91..cebe54e330 100644 --- a/fieldservice_account_analytic/data/ir_rule.xml +++ b/fieldservice_account_analytic/data/ir_rule.xml @@ -1,4 +1,3 @@ - account.analytic.line.fsm.manager diff --git a/fieldservice_account_analytic/migrations/12.0.2.0.0/post-migration.py b/fieldservice_account_analytic/migrations/12.0.2.0.0/post-migration.py deleted file mode 100644 index 1f7de1b3b7..0000000000 --- a/fieldservice_account_analytic/migrations/12.0.2.0.0/post-migration.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (C) 2019, Open Source Integrators -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - - -def migrate(env, version): - if not version: - return - - env.execute("UPDATE fsm_order SET bill_to = 'location' " "WHERE bill_to IS NULL;") diff --git a/fieldservice_account_analytic/models/__init__.py b/fieldservice_account_analytic/models/__init__.py index f42338c138..b1e4a7d50d 100644 --- a/fieldservice_account_analytic/models/__init__.py +++ b/fieldservice_account_analytic/models/__init__.py @@ -1,7 +1,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import ( - account_invoice_line, + account_move, analytic_account, fsm_location, fsm_order, diff --git a/fieldservice_account_analytic/models/account_invoice_line.py b/fieldservice_account_analytic/models/account_invoice_line.py deleted file mode 100644 index 21bb9c93a3..0000000000 --- a/fieldservice_account_analytic/models/account_invoice_line.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (C) 2018 - TODAY, Open Source Integrators -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo import _, api, models -from odoo.exceptions import ValidationError - - -class AccountInvoiceLine(models.Model): - _inherit = "account.invoice.line" - - @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_analytic_id"] = order.location_id.analytic_account_id.id - else: - raise ValidationError( - _("No analytic account " "set on the order's Location.") - ) - return super(AccountInvoiceLine, self).create(vals) diff --git a/fieldservice_account_analytic/models/account_move.py b/fieldservice_account_analytic/models/account_move.py new file mode 100644 index 0000000000..a9a2c29247 --- /dev/null +++ b/fieldservice_account_analytic/models/account_move.py @@ -0,0 +1,24 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + order = self.env["fsm.order"].browse(vals.get("fsm_order_id")) + if order: + if order.location_id.analytic_account_id: + vals[ + "analytic_account_id" + ] = order.location_id.analytic_account_id.id + else: + raise ValidationError( + _("No analytic account " "set on the order's Location.") + ) + return super(AccountMoveLine, self).create(vals_list) diff --git a/fieldservice_account_analytic/models/fsm_location.py b/fieldservice_account_analytic/models/fsm_location.py index d1fa677f92..40dbba9199 100644 --- a/fieldservice_account_analytic/models/fsm_location.py +++ b/fieldservice_account_analytic/models/fsm_location.py @@ -23,7 +23,7 @@ def get_default_customer(self): required=True, ondelete="restrict", auto_join=True, - track_visibility="onchange", + tracking=True, default=get_default_customer, ) diff --git a/fieldservice_account_analytic/models/fsm_order.py b/fieldservice_account_analytic/models/fsm_order.py index 77ab3e6264..c171a32ec8 100644 --- a/fieldservice_account_analytic/models/fsm_order.py +++ b/fieldservice_account_analytic/models/fsm_order.py @@ -15,12 +15,7 @@ class FSMOrder(models.Model): default="location", ) customer_id = fields.Many2one( - "res.partner", - string="Contact", - domain=[("customer", "=", True)], - change_default=True, - index=True, - track_visibility="always", + "res.partner", string="Contact", change_default=True, index=True, tracking=True, ) def _compute_total_cost(self): @@ -56,7 +51,6 @@ def _onchange_customer_id_location(self): if self.customer_id: self.location_id = self.customer_id.service_location_id - @api.multi def write(self, vals): res = super(FSMOrder, self).write(vals) for order in self: