diff --git a/tms_account/__manifest__.py b/tms_account/__manifest__.py
index 2f678fbc..f65583ed 100644
--- a/tms_account/__manifest__.py
+++ b/tms_account/__manifest__.py
@@ -5,16 +5,15 @@
"name": "TMS - Accounting",
"summary": "Track invoices linked to TMS orders",
"version": "17.0.1.0.0",
- "category": "Field Service",
+ "category": "Warehouse Management",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-transport",
- "depends": ["tms", "tms_sale", "tms_expense", "tms_purchase", "account_usability"],
+ "depends": ["tms_sale", "tms_expense", "tms_purchase", "account_usability"],
"data": [
- "security/res_groups.xml",
"data/analytic_plan.xml",
+ "security/res_groups.xml",
"views/res_config_settings.xml",
"views/account_move.xml",
- "views/account_analytic_plan.xml",
"views/tms_order.xml",
"views/tms_route.xml",
],
diff --git a/tms_account/data/analytic_plan.xml b/tms_account/data/analytic_plan.xml
index 68f5c9e0..a9ba608d 100644
--- a/tms_account/data/analytic_plan.xml
+++ b/tms_account/data/analytic_plan.xml
@@ -2,11 +2,10 @@
Routes
- True
+
Trips
- True
diff --git a/tms_account/models/__init__.py b/tms_account/models/__init__.py
index dc3cdbf0..4c4c5c95 100644
--- a/tms_account/models/__init__.py
+++ b/tms_account/models/__init__.py
@@ -1,12 +1,11 @@
-from . import account_analytic_plan
-from . import res_config_settings
-from . import tms_order
-from . import analytic_account
-from . import tms_route
-from . import account_move
-from . import account_move_line
-from . import purchase_order_line
-from . import hr_expense
-from . import sale_order_line
-from . import sale_order
-from . import account_analytic_line
+from . import (
+ tms_order,
+ tms_route,
+ account_move,
+ account_move_line,
+ purchase_order_line,
+ hr_expense,
+ sale_order_line,
+ sale_order,
+ account_analytic_line,
+)
diff --git a/tms_account/models/account_analytic_plan.py b/tms_account/models/account_analytic_plan.py
deleted file mode 100644
index 2d163eb2..00000000
--- a/tms_account/models/account_analytic_plan.py
+++ /dev/null
@@ -1,14 +0,0 @@
-# Copyright (C) 2024 Open Source Integrators
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import fields, models
-
-
-class AccountAnalyticPlan(models.Model):
- _inherit = "account.analytic.plan"
-
- tms_flag = fields.Boolean(
- string="Used for Transports?",
- help="""This plan is used as a default in the Transport application.
- """,
- readonly=True,
- )
diff --git a/tms_account/models/account_move_line.py b/tms_account/models/account_move_line.py
index 2f424f02..b959911c 100644
--- a/tms_account/models/account_move_line.py
+++ b/tms_account/models/account_move_line.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2019 Open Source Integrators
+# Copyright (C) 2024 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.tools import frozendict
diff --git a/tms_account/models/analytic_account.py b/tms_account/models/analytic_account.py
deleted file mode 100644
index 283a2071..00000000
--- a/tms_account/models/analytic_account.py
+++ /dev/null
@@ -1,10 +0,0 @@
-# Copyright (C) 2024 Open Source Integrators
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import fields, models
-
-
-class AnalyticAccount(models.Model):
- _inherit = "account.analytic.account"
-
- trip_id = fields.One2many("tms.order", "analytic_account_id", copy=False)
- route_id = fields.One2many("tms.route", "analytic_account_id", copy=False)
diff --git a/tms_account/models/hr_expense.py b/tms_account/models/hr_expense.py
index 7e00ae7c..7f4db5a1 100644
--- a/tms_account/models/hr_expense.py
+++ b/tms_account/models/hr_expense.py
@@ -1,3 +1,5 @@
+# Copyright (C) 2024 Open Source Integrators
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
diff --git a/tms_account/models/purchase_order_line.py b/tms_account/models/purchase_order_line.py
index e6c50ef2..75fbbca8 100644
--- a/tms_account/models/purchase_order_line.py
+++ b/tms_account/models/purchase_order_line.py
@@ -1,3 +1,5 @@
+# Copyright (C) 2024 Open Source Integrators
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
diff --git a/tms_account/models/res_config_settings.py b/tms_account/models/res_config_settings.py
deleted file mode 100644
index 44b00e65..00000000
--- a/tms_account/models/res_config_settings.py
+++ /dev/null
@@ -1,76 +0,0 @@
-# Copyright (C) 2018 - TODAY, Open Source Integrators
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-
-import ast
-
-from odoo import api, fields, models
-
-
-class ResConfigSettings(models.TransientModel):
- _inherit = "res.config.settings"
-
- group_tms_route_analytic_plan = fields.Boolean(
- implied_group="tms_account.group_tms_route_analytic_plan",
- compute="_compute_tms_analytic_groups",
- )
- group_tms_order_analytic_plan = fields.Boolean(
- implied_group="tms_account.group_tms_order_analytic_plan",
- compute="_compute_tms_analytic_groups",
- )
-
- tms_analytic_plan = fields.Many2many(
- "account.analytic.plan",
- )
-
- tms_analytic_plan_domain = fields.Char(
- default="[]",
- store=True,
- compute="_compute_tms_analytic_plan_domain",
- readonly=False,
- )
-
- @api.depends("tms_analytic_plan", "group_tms_route", "group_analytic_accounting")
- def _compute_tms_analytic_plan_domain(self):
- if not self.group_tms_route:
- domain = [
- ("tms_flag", "=", True),
- ("id", "!=", self.env.ref("tms_account.tms_route_analytic_plan").id),
- ]
- else:
- domain = [("tms_flag", "=", True)]
- self.tms_analytic_plan_domain = domain
-
- @api.model
- def get_values(self):
- res = super().get_values()
- parameter = self.env["ir.config_parameter"].sudo()
- tms_analytic_plan_ids = parameter.get_param(
- "tms_account.tms_analytic_plan_ids", default="[]"
- )
- tms_analytic_plan_ids = ast.literal_eval(tms_analytic_plan_ids)
- res.update(
- tms_analytic_plan=[(6, 0, tms_analytic_plan_ids)]
- if tms_analytic_plan_ids
- else False,
- )
- return res
-
- def set_values(self):
- res = super().set_values()
- parameter = self.env["ir.config_parameter"].sudo()
- parameter.set_param(
- "tms_account.tms_analytic_plan_ids", self.tms_analytic_plan.ids
- )
- return res
-
- @api.depends("tms_analytic_plan")
- def _compute_tms_analytic_groups(self):
- for record in self:
- record.group_tms_route_analytic_plan = False
- record.group_tms_order_analytic_plan = False
-
- for plan in record.tms_analytic_plan:
- if plan == self.env.ref("tms_account.tms_route_analytic_plan"):
- record.group_tms_route_analytic_plan = True
- if plan == self.env.ref("tms_account.tms_order_analytic_plan"):
- record.group_tms_order_analytic_plan = True
diff --git a/tms_account/models/sale_order.py b/tms_account/models/sale_order.py
index 8ed6d875..a751d8ac 100644
--- a/tms_account/models/sale_order.py
+++ b/tms_account/models/sale_order.py
@@ -1,6 +1,5 @@
-# Copyright (C) 2019 Open Source Integrators
+# Copyright (C) 2024 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-
from odoo import api, models
diff --git a/tms_account/models/sale_order_line.py b/tms_account/models/sale_order_line.py
index 7f01984e..24837652 100644
--- a/tms_account/models/sale_order_line.py
+++ b/tms_account/models/sale_order_line.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2019 Open Source Integrators
+# Copyright (C) 2024 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
from odoo.fields import Command
@@ -15,23 +15,17 @@ def _default_analytic_distribution(self):
trip_count = len(self.tms_order_ids)
percentage_per_trip = 100 / trip_count
- route_analytic_plan_group = self.env.ref(
- "tms_account.group_tms_route_analytic_plan"
- )
- order_analytic_plan_group = self.env.ref(
- "tms_account.group_tms_order_analytic_plan"
- )
analytic_account_ids = []
trip_id = self.env["tms.order"].browse(trip.id)
- if trip_id.route_id and route_analytic_plan_group:
- analytic_account_id = trip_id.route_id.analytic_account_id.id
+ if trip_id:
+ analytic_account_id = trip_id.analytic_account_id.id
if analytic_account_id:
analytic_account_ids.append(str(analytic_account_id))
- if order_analytic_plan_group:
- analytic_account_id = trip_id.analytic_account_id.id
+ if trip_id.route_id:
+ analytic_account_id = trip_id.route_id.analytic_account_id.id
if analytic_account_id:
analytic_account_ids.append(str(analytic_account_id))
@@ -40,7 +34,6 @@ def _default_analytic_distribution(self):
total_distribution[distribution_key] = percentage_per_trip
self.analytic_distribution = total_distribution
-
return total_distribution
def _prepare_invoice_line(self, **optional_values):
diff --git a/tms_account/models/tms_order.py b/tms_account/models/tms_order.py
index e41e959b..6fd8ba4c 100644
--- a/tms_account/models/tms_order.py
+++ b/tms_account/models/tms_order.py
@@ -43,17 +43,13 @@ def _compute_total_revenue(self):
@api.model
def create(self, vals):
order = super().create(vals)
- if self.env.user.has_group(
- "analytic.group_analytic_accounting"
- ) and self.env.user.has_group("tms_account.group_tms_order_analytic_plan"):
- analytic_account = self.env["account.analytic.account"].create(
- {
- "name": vals.get("name"),
- "plan_id": self.env.ref("tms_account.tms_order_analytic_plan").id,
- "trip_id": order,
- }
- )
- order.analytic_account_id = analytic_account
+ analytic_account = self.env["account.analytic.account"].create(
+ {
+ "name": vals.get("name"),
+ "plan_id": self.env.ref("tms_account.tms_order_analytic_plan").id,
+ }
+ )
+ order.analytic_account_id = analytic_account.id
return order
@api.model
@@ -100,41 +96,19 @@ def _default_analytic_distribution(self):
# Initialize distribution dictionary
distribution = {}
- # Fetch the analytic accounts based on group names
- route_analytic_plan_group = self.env.ref(
- "tms_account.group_tms_route_analytic_plan"
- )
- order_analytic_plan_group = self.env.ref(
- "tms_account.group_tms_order_analytic_plan"
- )
-
analytic_account_ids = []
# Iterate over tms_order_ids to determine analytic accounts
for tms_order in self.sale_id.tms_order_ids:
- if tms_order.route_id and route_analytic_plan_group:
- analytic_account_id = tms_order.route_id.analytic_account_id.id
- analytic_accounts = self.env["account.analytic.account"].search(
- [("id", "=", analytic_account_id)]
- )
- account_id = str(analytic_accounts.id)
- if account_id:
- analytic_account_ids.append(account_id)
-
- if order_analytic_plan_group:
- analytic_account_id = tms_order.analytic_account_id.id
- analytic_accounts = self.env["account.analytic.account"].search(
- [("id", "=", analytic_account_id)]
- )
- account_id = str(analytic_accounts.id)
- if account_id:
- analytic_account_ids.append(account_id)
+ if tms_order.route_id and tms_order.route_id.analytic_account_id:
+ analytic_account_ids.append(tms_order.route_id.analytic_account_id.id)
+ if tms_order.analytic_account_id:
+ analytic_account_ids.append(tms_order.analytic_account_id.id)
# Ensure distribution is provided with unique analytic accounts
analytic_account_ids = list(set(analytic_account_ids))
if analytic_account_ids:
distribution[", ".join(analytic_account_ids)] = 100
-
return distribution
def _handle_bills(self):
diff --git a/tms_account/models/tms_route.py b/tms_account/models/tms_route.py
index d05d3243..f864053e 100644
--- a/tms_account/models/tms_route.py
+++ b/tms_account/models/tms_route.py
@@ -6,7 +6,6 @@
class TMSRoute(models.Model):
_inherit = "tms.route"
- analytic_plan_id = fields.Many2one("account.analytic.plan")
analytic_account_id = fields.Many2one(
"account.analytic.account",
domain=[("plan_id", "=", "%(tms_account.tms_route_analytic_plan)d")],
@@ -34,16 +33,13 @@ def _compute_total_revenue(self):
@api.model
def create(self, vals_list):
route = super().create(vals_list)
- if self.env.user.has_group("tms_account.group_tms_route_analytic_plan"):
- # If analytic account not provided
- if vals_list.get("analytic_account_id") in [False, None]:
- # Create analytic account
- analytic_plan = self.env.ref("tms_account.tms_route_analytic_plan")
- account_vals_list = {"name": route.name, "plan_id": analytic_plan.id}
- AccountAnalyticAccount = self.env["account.analytic.account"]
- account = AccountAnalyticAccount.create(account_vals_list)
-
- # Set the analytic_account_id
- route.analytic_account_id = account.id
-
+ # If analytic account not provided
+ if vals_list.get("analytic_account_id") in [False, None]:
+ # Create analytic account
+ plan = self.env.ref("tms_account.tms_route_analytic_plan")
+ analytic = self.env["account.analytic.account"].create(
+ {"name": route.name, "plan_id": plan.id}
+ )
+ # Set the analytic_account_id
+ route.analytic_account_id = analytic.id
return route
diff --git a/tms_account/views/account_analytic_plan.xml b/tms_account/views/account_analytic_plan.xml
deleted file mode 100644
index f89770fe..00000000
--- a/tms_account/views/account_analytic_plan.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
- account.analytic.plan.form.inherit.tms.account
- account.analytic.plan
-
-
-
-
-
-
-
-
-
diff --git a/tms_account/views/res_config_settings.xml b/tms_account/views/res_config_settings.xml
index c3f3d800..2180514d 100644
--- a/tms_account/views/res_config_settings.xml
+++ b/tms_account/views/res_config_settings.xml
@@ -5,20 +5,12 @@
-
-
+
-
-
diff --git a/tms_account/views/tms_order.xml b/tms_account/views/tms_order.xml
index 67d0fb60..76848882 100644
--- a/tms_account/views/tms_order.xml
+++ b/tms_account/views/tms_order.xml
@@ -45,6 +45,16 @@
invisible="not sale_id and not purchase_ids"
/>
+
+
+
+
+
+
+
+
+
+
diff --git a/tms_account/views/tms_route.xml b/tms_account/views/tms_route.xml
index 1d4740be..9480bbc4 100644
--- a/tms_account/views/tms_route.xml
+++ b/tms_account/views/tms_route.xml
@@ -7,11 +7,14 @@
-
-
+
+
+
+
+