Skip to content

Commit

Permalink
[MIG] fieldservice_account_analytic: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliette BLANC authored and michelerusti committed Nov 13, 2023
1 parent 4312cc0 commit 1692796
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 52 deletions.
2 changes: 1 addition & 1 deletion fieldservice_account_analytic/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Field Service - Analytic Accounting",
"summary": """Track analytic accounts on Field Service locations
and orders""",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Field Service",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/field-service",
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions fieldservice_account_analytic/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class AccountMoveLine(models.Model):
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("fsm_order_ids") and vals.get("fsm_order_ids")[0][2]:
if vals.get("fsm_order_ids") and len(vals.get("fsm_order_ids")[0]) > 2:
fsm_orders = vals.get("fsm_order_ids")[0][2]
for order in self.env["fsm.order"].browse(fsm_orders).exists():
if order.location_id.analytic_account_id:
vals[
"analytic_account_id"
] = order.location_id.analytic_account_id.id
vals["analytic_distribution"] = {
order.location_id.analytic_account_id.id: 100
}
else:
raise ValidationError(
_("No analytic account " "set on the order's Location.")
Expand Down
2 changes: 1 addition & 1 deletion fieldservice_account_analytic/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FSMOrder(models.Model):
"res.partner",
string="Contact",
change_default=True,
index=True,
index="btree",
tracking=True,
)

Expand Down
77 changes: 40 additions & 37 deletions fieldservice_account_analytic/tests/test_fsm_account_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,73 +9,76 @@


class FSMAccountAnalyticCase(TransactionCase):
def setUp(self):
super(FSMAccountAnalyticCase, self).setUp()
self.Wizard = self.env["fsm.wizard"]
self.WorkOrder = self.env["fsm.order"]
self.AccountInvoice = self.env["account.move"]
self.AccountInvoiceLine = self.env["account.move.line"]
@classmethod
def setUpClass(cls):
super(FSMAccountAnalyticCase, cls).setUpClass()
cls.Wizard = cls.env["fsm.wizard"]
cls.WorkOrder = cls.env["fsm.order"]
cls.AccountInvoice = cls.env["account.move"]
cls.AccountInvoiceLine = cls.env["account.move.line"]
# create a Res Partner
self.test_partner = self.env["res.partner"].create(
cls.test_partner = cls.env["res.partner"].create(
{"name": "Test Partner", "phone": "123", "email": "tp@email.com"}
)
# create a Res Partner to be converted to FSM Location/Person
self.test_loc_partner = self.env["res.partner"].create(
cls.test_loc_partner = cls.env["res.partner"].create(
{"name": "Test Loc Partner", "phone": "ABC", "email": "tlp@email.com"}
)
self.test_loc_partner2 = self.env["res.partner"].create(
cls.test_loc_partner2 = cls.env["res.partner"].create(
{"name": "Test Loc Partner 2", "phone": "123", "email": "tlp@example.com"}
)
# create expected FSM Location to compare to converted FSM Location
self.test_location = self.env["fsm.location"].create(
cls.test_location = cls.env["fsm.location"].create(
{
"name": "Test Location",
"phone": "123",
"email": "tp@email.com",
"partner_id": self.test_loc_partner.id,
"owner_id": self.test_loc_partner.id,
"customer_id": self.test_loc_partner.id,
"partner_id": cls.test_loc_partner.id,
"owner_id": cls.test_loc_partner.id,
"customer_id": cls.test_loc_partner.id,
}
)
self.location = self.env["fsm.location"].create(
cls.location = cls.env["fsm.location"].create(
{
"name": "Location 1",
"phone": "123",
"email": "tp@email.com",
"partner_id": self.test_loc_partner.id,
"owner_id": self.test_loc_partner.id,
"customer_id": self.test_loc_partner.id,
"partner_id": cls.test_loc_partner.id,
"owner_id": cls.test_loc_partner.id,
"customer_id": cls.test_loc_partner.id,
}
)
self.test_analytic_account = self.env["account.analytic.account"].create(
{"name": "test_analytic_account"}
cls.test_analytic_plan = cls.env["account.analytic.plan"].create(
{"name": "test_analytic_plan"}
)
self.test_location2 = self.env["fsm.location"].create(
cls.test_analytic_account = cls.env["account.analytic.account"].create(
{
"name": "test_analytic_account",
"plan_id": cls.test_analytic_plan.id,
}
)
cls.test_location2 = cls.env["fsm.location"].create(
{
"name": "Test Location 2",
"phone": "123",
"email": "tp@email.com",
"partner_id": self.test_loc_partner2.id,
"owner_id": self.test_loc_partner2.id,
"customer_id": self.test_loc_partner2.id,
"fsm_parent_id": self.test_location.id,
"analytic_account_id": self.test_analytic_account.id,
"partner_id": cls.test_loc_partner2.id,
"owner_id": cls.test_loc_partner2.id,
"customer_id": cls.test_loc_partner2.id,
"fsm_parent_id": cls.test_location.id,
"analytic_account_id": cls.test_analytic_account.id,
}
)
self.default_account_revenue = self.env["account.account"].search(
cls.default_account_revenue = cls.env["account.account"].search(
[
("company_id", "=", self.env.user.company_id.id),
(
"user_type_id",
"=",
self.env.ref("account.data_account_type_revenue").id,
),
("company_id", "=", cls.env.user.company_id.id),
("account_type", "=", "income"),
],
limit=1,
)
self.move_line = self.env["account.move.line"]
self.analytic_line = self.env["account.analytic.line"]
self.product1 = self.env["product.product"].create(
cls.move_line = cls.env["account.move.line"]
cls.analytic_line = cls.env["account.analytic.line"]
cls.product1 = cls.env["product.product"].create(
{
"name": "Product A",
"detailed_type": "consu",
Expand Down Expand Up @@ -149,7 +152,7 @@ def test_fsm_orders_1(self):
[
{
"account_id": self.default_account_revenue.id,
"analytic_account_id": self.test_analytic_account.id,
"analytic_distribution": {self.test_analytic_account.id: 100},
"fsm_order_ids": [(6, 0, order2.ids)],
"move_id": general_move1.id,
}
Expand All @@ -159,7 +162,7 @@ def test_fsm_orders_1(self):
self.move_line.create(
{
"account_id": self.default_account_revenue.id,
"analytic_account_id": self.test_analytic_account.id,
"analytic_account_id": {self.test_analytic_account.id: 100},
"fsm_order_ids": [(6, 0, order.ids)],
}
)
Expand Down

0 comments on commit 1692796

Please sign in to comment.