Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] fieldservice_account + fieldservice_sale: Post-install test + fallback to load CoA #1332

Merged
merged 4 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
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
73 changes: 44 additions & 29 deletions fieldservice_account/tests/test_fsm_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,70 @@

from datetime import datetime, timedelta

from odoo.tests import tagged
from odoo.tests.common import TransactionCase


@tagged("-at_install", "post_install")
class FSMAccountCase(TransactionCase):
def setUp(self):
super(FSMAccountCase, 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().setUpClass()
if not cls.env.company.chart_template_id:
# Load a CoA if there's none in current company
coa = cls.env.ref("l10n_generic_coa.configurable_chart_template", False)

Check warning on line 17 in fieldservice_account/tests/test_fsm_account.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_account/tests/test_fsm_account.py#L17

Added line #L17 was not covered by tests
if not coa:
# Load the first available CoA
coa = cls.env["account.chart.template"].search(

Check warning on line 20 in fieldservice_account/tests/test_fsm_account.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_account/tests/test_fsm_account.py#L20

Added line #L20 was not covered by tests
[("visible", "=", True)], limit=1
)
coa.try_loading(company=cls.env.company, install_demo=False)

Check warning on line 23 in fieldservice_account/tests/test_fsm_account.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_account/tests/test_fsm_account.py#L23

Added line #L23 was not covered by tests
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(
{
"name": "Test Location",
"phone": "123",
"email": "tp@email.com",
"partner_id": self.test_loc_partner.id,
"owner_id": self.test_loc_partner.id,
}
cls.test_location = (
cls.env["fsm.location"]
.with_context(default_owner_id=cls.test_loc_partner.id)
.create(
{
"name": "Test Location",
"phone": "123",
"email": "tp@email.com",
"partner_id": cls.test_loc_partner.id,
}
)
)
self.test_order = self.env["fsm.order"].create(
cls.test_order = cls.env["fsm.order"].create(
{
"location_id": self.test_location.id,
"location_id": cls.test_location.id,
"date_start": datetime.today(),
"date_end": datetime.today() + timedelta(hours=2),
"request_early": datetime.today(),
}
)
self.test_order2 = self.env["fsm.order"].create(
cls.test_order2 = cls.env["fsm.order"].create(
{
"location_id": self.test_location.id,
"location_id": cls.test_location.id,
"date_start": datetime.today(),
"date_end": datetime.today() + timedelta(hours=2),
"request_early": datetime.today(),
}
)
company = self.env.user.company_id
self.default_account_revenue = self.env["account.account"].search(
company = cls.env.user.company_id
cls.default_account_revenue = cls.env["account.account"].search(
[
("company_id", "=", company.id),
("account_type", "=", "income"),
Expand All @@ -64,9 +79,9 @@
limit=1,
)

self.test_invoice = self.env["account.move"].create(
cls.test_invoice = cls.env["account.move"].create(
{
"partner_id": self.test_partner.id,
"partner_id": cls.test_partner.id,
"move_type": "out_invoice",
"invoice_date": datetime.today().date(),
"invoice_line_ids": [
Expand All @@ -86,23 +101,23 @@
0,
{
"name": "line_debit",
"account_id": self.default_account_revenue.id,
"account_id": cls.default_account_revenue.id,
},
),
(
0,
0,
{
"name": "line_credit",
"account_id": self.default_account_revenue.id,
"account_id": cls.default_account_revenue.id,
},
),
],
}
)
self.test_invoice2 = self.env["account.move"].create(
cls.test_invoice2 = cls.env["account.move"].create(
{
"partner_id": self.test_partner.id,
"partner_id": cls.test_partner.id,
"move_type": "out_invoice",
"invoice_date": datetime.today().date(),
"invoice_line_ids": [
Expand Down
11 changes: 11 additions & 0 deletions fieldservice_account_analytic/models/fsm_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ class FSMLocation(models.Model):
"account.analytic.account", string="Analytic Account", company_dependent=True
)

@api.model
def default_get(self, fields):
res = super().default_get(fields)
if (
res.get("owner_id")
and "customer_id" in fields
and not res.get("customer_id")
):
res["customer_id"] = res.get("owner_id")
return res

@api.model
def get_default_customer(self):
if self.fsm_parent_id:
Expand Down
17 changes: 14 additions & 3 deletions fieldservice_sale/tests/test_fsm_sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@

from odoo import fields
from odoo.exceptions import ValidationError
from odoo.tests import tagged

from .test_fsm_sale_common import TestFSMSale


@tagged("-at_install", "post_install")
class TestFSMSaleOrder(TestFSMSale):
@classmethod
def setUpClass(cls):
super(TestFSMSaleOrder, cls).setUpClass()
super().setUpClass()
if not cls.env.company.chart_template_id:
# Load a CoA if there's none in current company
coa = cls.env.ref("l10n_generic_coa.configurable_chart_template", False)

Check warning on line 18 in fieldservice_sale/tests/test_fsm_sale_order.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_sale/tests/test_fsm_sale_order.py#L18

Added line #L18 was not covered by tests
if not coa:
# Load the first available CoA
coa = cls.env["account.chart.template"].search(

Check warning on line 21 in fieldservice_sale/tests/test_fsm_sale_order.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_sale/tests/test_fsm_sale_order.py#L21

Added line #L21 was not covered by tests
[("visible", "=", True)], limit=1
)
coa.try_loading(company=cls.env.company, install_demo=False)

Check warning on line 24 in fieldservice_sale/tests/test_fsm_sale_order.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_sale/tests/test_fsm_sale_order.py#L24

Added line #L24 was not covered by tests
cls.test_location = cls.env.ref("fieldservice.test_location")

# Setup products that when sold will create some FSM orders
Expand All @@ -21,8 +32,8 @@
"company_id": False,
}
)
cls.pricelist_usd = cls.env["product.pricelist"].search(
[("currency_id.name", "=", "USD")], limit=1
cls.pricelist_usd = cls.env["product.pricelist"].create(
{"name": "Test pricelist", "currency_id": cls.env.company.currency_id.id}
)
# Create some sale orders that will use the above products
SaleOrder = cls.env["sale.order"].with_context(tracking_disable=True)
Expand Down