From 28bdae523f1930ae052cb1521d1b884cee6f2245 Mon Sep 17 00:00:00 2001 From: Benoit Aimont Date: Wed, 28 Apr 2021 09:57:44 +0200 Subject: [PATCH] [MIG] fieldservice_isp_account: Migration to 13.0 --- fieldservice_isp_account/README.rst | 14 +- fieldservice_isp_account/__manifest__.py | 3 +- fieldservice_isp_account/i18n/es_AR.po | 6 +- fieldservice_isp_account/i18n/es_CL.po | 6 +- .../i18n/fieldservice_isp_account.pot | 6 +- fieldservice_isp_account/i18n/pt_BR.po | 6 +- fieldservice_isp_account/models/__init__.py | 2 +- .../models/account_invoice_line.py | 39 ------ fieldservice_isp_account/models/fsm_order.py | 131 ++++++++++++------ .../models/fsm_order_cost.py | 24 ++++ fieldservice_isp_account/models/fsm_person.py | 9 +- .../security/fsm_order_cost.xml | 23 +++ .../static/description/index.html | 6 +- .../tests/test_isp_account.py | 69 +++++---- fieldservice_isp_account/views/account.xml | 1 - fieldservice_isp_account/views/fsm_order.xml | 22 ++- 16 files changed, 209 insertions(+), 158 deletions(-) delete mode 100644 fieldservice_isp_account/models/account_invoice_line.py create mode 100644 fieldservice_isp_account/models/fsm_order_cost.py create mode 100644 fieldservice_isp_account/security/fsm_order_cost.xml diff --git a/fieldservice_isp_account/README.rst b/fieldservice_isp_account/README.rst index cb1c58ed6b..5b7501afeb 100644 --- a/fieldservice_isp_account/README.rst +++ b/fieldservice_isp_account/README.rst @@ -14,16 +14,16 @@ Field Service - ISP Accounting :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ffield--service-lightgray.png?logo=github - :target: https://github.com/OCA/field-service/tree/12.0/fieldservice_isp_account + :target: https://github.com/OCA/field-service/tree/13.0/fieldservice_isp_account :alt: OCA/field-service .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/field-service-12-0/field-service-12-0-fieldservice_isp_account + :target: https://translation.odoo-community.org/projects/field-service-13-0/field-service-13-0-fieldservice_isp_account :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/264/12.0 + :target: https://runbot.odoo-community.org/runbot/264/13.0 :alt: Try me on Runbot -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| This module adds the ability to track employee time and contractor costs for Field Service Orders. It also adds functionality to create @@ -67,7 +67,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -118,8 +118,8 @@ promote its widespread use. Current `maintainers `__: -|maintainer-osimallen| |maintainer-brian10048| |maintainer-bodedra| +|maintainer-osimallen| |maintainer-brian10048| |maintainer-bodedra| -This module is part of the `OCA/field-service `_ project on GitHub. +This module is part of the `OCA/field-service `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/fieldservice_isp_account/__manifest__.py b/fieldservice_isp_account/__manifest__.py index 55cc326f83..3c0f211449 100644 --- a/fieldservice_isp_account/__manifest__.py +++ b/fieldservice_isp_account/__manifest__.py @@ -5,7 +5,7 @@ "name": "Field Service - ISP Accounting", "summary": """Invoice Field Service orders based on employee time or contractor costs""", - "version": "12.0.2.3.2", + "version": "13.0.1.0.0", "category": "Field Service", "author": "Open Source Integrators, Odoo Community Association (OCA)", "website": "https://github.com/OCA/field-service", @@ -15,6 +15,7 @@ "hr_timesheet", ], "data": [ + "security/fsm_order_cost.xml", "security/ir.model.access.csv", "data/time_products.xml", "views/account.xml", diff --git a/fieldservice_isp_account/i18n/es_AR.po b/fieldservice_isp_account/i18n/es_AR.po index 2c5c799966..32b7a899ee 100644 --- a/fieldservice_isp_account/i18n/es_AR.po +++ b/fieldservice_isp_account/i18n/es_AR.po @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" "PO-Revision-Date: 2020-07-21 05:19+0000\n" "Last-Translator: Ignacio Buioli \n" @@ -128,7 +128,7 @@ msgid "Hour(s)" msgstr "Hora(s)" #. module: fieldservice_isp_account -#: model:ir.model,name:fieldservice_isp_account.model_account_invoice_line +#: model:ir.model,name:fieldservice_isp_account.model_account_move_line msgid "Invoice Line" msgstr "Línea de Factura" @@ -167,7 +167,7 @@ msgstr "" " " #. module: fieldservice_isp_account -#: code:addons/fieldservice_isp_account/models/account_invoice_line.py:19 +#: code:addons/fieldservice_isp_account/models/account_move_line.py:19 #, python-format msgid "Please set the field service worker." msgstr "Por favor configure el trabajador de servicio de campo." diff --git a/fieldservice_isp_account/i18n/es_CL.po b/fieldservice_isp_account/i18n/es_CL.po index 8c1be242e8..25b3c15534 100644 --- a/fieldservice_isp_account/i18n/es_CL.po +++ b/fieldservice_isp_account/i18n/es_CL.po @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" "PO-Revision-Date: 2020-01-16 22:38+0000\n" "Last-Translator: Nelson Ramírez Sánchez \n" @@ -128,7 +128,7 @@ msgid "Hour(s)" msgstr "" #. module: fieldservice_isp_account -#: model:ir.model,name:fieldservice_isp_account.model_account_invoice_line +#: model:ir.model,name:fieldservice_isp_account.model_account_move_line msgid "Invoice Line" msgstr "" @@ -165,7 +165,7 @@ msgid "Overtime for Field Service Employees\n" msgstr "" #. module: fieldservice_isp_account -#: code:addons/fieldservice_isp_account/models/account_invoice_line.py:19 +#: code:addons/fieldservice_isp_account/models/account_move_line.py:19 #, python-format msgid "Please set the field service worker." msgstr "" diff --git a/fieldservice_isp_account/i18n/fieldservice_isp_account.pot b/fieldservice_isp_account/i18n/fieldservice_isp_account.pot index c633f9becc..8c87b45cf6 100644 --- a/fieldservice_isp_account/i18n/fieldservice_isp_account.pot +++ b/fieldservice_isp_account/i18n/fieldservice_isp_account.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: <>\n" "Language-Team: \n" @@ -121,7 +121,7 @@ msgid "Hour(s)" msgstr "" #. module: fieldservice_isp_account -#: model:ir.model,name:fieldservice_isp_account.model_account_invoice_line +#: model:ir.model,name:fieldservice_isp_account.model_account_move_line msgid "Invoice Line" msgstr "" @@ -158,7 +158,7 @@ msgid "Overtime for Field Service Employees\n" msgstr "" #. module: fieldservice_isp_account -#: code:addons/fieldservice_isp_account/models/account_invoice_line.py:19 +#: code:addons/fieldservice_isp_account/models/account_move_line.py:19 #, python-format msgid "Please set the field service worker." msgstr "" diff --git a/fieldservice_isp_account/i18n/pt_BR.po b/fieldservice_isp_account/i18n/pt_BR.po index bcf8c1ad34..907151e7dc 100644 --- a/fieldservice_isp_account/i18n/pt_BR.po +++ b/fieldservice_isp_account/i18n/pt_BR.po @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" "PO-Revision-Date: 2020-06-17 16:19+0000\n" "Last-Translator: Fernando Colus \n" @@ -128,7 +128,7 @@ msgid "Hour(s)" msgstr "Hora(s)" #. module: fieldservice_isp_account -#: model:ir.model,name:fieldservice_isp_account.model_account_invoice_line +#: model:ir.model,name:fieldservice_isp_account.model_account_move_line msgid "Invoice Line" msgstr "Linha de Fatura" @@ -167,7 +167,7 @@ msgstr "" " " #. module: fieldservice_isp_account -#: code:addons/fieldservice_isp_account/models/account_invoice_line.py:19 +#: code:addons/fieldservice_isp_account/models/account_move_line.py:19 #, python-format msgid "Please set the field service worker." msgstr "Por favor, selecione o trabalhador do serviço de campo." diff --git a/fieldservice_isp_account/models/__init__.py b/fieldservice_isp_account/models/__init__.py index 19e859522b..a2be44257e 100644 --- a/fieldservice_isp_account/models/__init__.py +++ b/fieldservice_isp_account/models/__init__.py @@ -1,7 +1,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import ( - account_invoice_line, fsm_order, fsm_person, ) +from . import fsm_order_cost diff --git a/fieldservice_isp_account/models/account_invoice_line.py b/fieldservice_isp_account/models/account_invoice_line.py deleted file mode 100644 index 9a59be9fc0..0000000000 --- a/fieldservice_isp_account/models/account_invoice_line.py +++ /dev/null @@ -1,39 +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.onchange("product_id", "quantity") - def onchange_product_id(self): - for line in self: - if line.fsm_order_id: - partner = ( - line.fsm_order_id.person_id - and line.fsm_order_id.person_id.partner_id - or False - ) - if not partner: - raise ValidationError(_("Please set the field service worker.")) - fpos = partner.property_account_position_id - tmpl = line.product_id.product_tmpl_id - if line.product_id: - accounts = tmpl.get_product_accounts() - supinfo = self.env["product.supplierinfo"].search( - [ - ("name", "=", partner.id), - ("product_tmpl_id", "=", tmpl.id), - ("min_qty", "<=", line.quantity), - ], - order="min_qty DESC", - ) - line.price_unit = ( - supinfo and supinfo[0].price or tmpl.standard_price - ) - line.account_id = accounts.get("expense", False) - line.invoice_line_tax_ids = fpos.map_tax(tmpl.supplier_taxes_id) - line.name = line.product_id.name diff --git a/fieldservice_isp_account/models/fsm_order.py b/fieldservice_isp_account/models/fsm_order.py index 81c3af3aa1..68762b024e 100644 --- a/fieldservice_isp_account/models/fsm_order.py +++ b/fieldservice_isp_account/models/fsm_order.py @@ -17,7 +17,7 @@ class FSMOrder(models.Model): _inherit = "fsm.order" contractor_cost_ids = fields.One2many( - "account.invoice.line", "fsm_order_id", string="Contractor Costs" + "fsm.order.cost", "fsm_order_id", string="Contractor Costs" ) employee_timesheet_ids = fields.One2many( "account.analytic.line", "fsm_order_id", string="Employee Timesheets" @@ -38,6 +38,8 @@ def _compute_employee(self): for order in self: if user.employee_ids: order.employee = True + else: + order.employee = False @api.depends("employee_timesheet_ids", "contractor_cost_ids") def _compute_total_cost(self): @@ -68,11 +70,11 @@ def _compute_contractor_cost(self): def action_complete(self): for order in self: order.account_stage = "review" - if self.person_id.supplier and not self.contractor_cost_ids: + if self.person_id.supplier_rank and not self.contractor_cost_ids: raise ValidationError( _("Cannot move to Complete " + "until 'Contractor Costs' is filled in") ) - if not self.person_id.supplier and not self.employee_timesheet_ids: + if not self.person_id.supplier_rank and not self.employee_timesheet_ids: raise ValidationError( _( "Cannot move to Complete until " @@ -84,29 +86,51 @@ def action_complete(self): def create_bills(self): jrnl = self.env["account.journal"].search( [ - ("company_id", "=", self.env.user.company_id.id), + ("company_id", "=", self.env.company.id), ("type", "=", "purchase"), ("active", "=", True), ], limit=1, ) - fpos = self.customer_id.property_account_position_id + fpos = self.person_id.partner_id.property_account_position_id + invoice_line_vals = [] + for cost in self.contractor_cost_ids: + template = cost.product_id.product_tmpl_id + accounts = template.get_product_accounts() + account = accounts["expense"] + taxes = template.supplier_taxes_id + tax_ids = fpos.map_tax(taxes) + invoice_line_vals.append( + ( + 0, + 0, + { + "analytic_account_id": self.location_id.analytic_account_id.id, + "product_id": cost.product_id.id, + "quantity": cost.quantity, + "name": cost.product_id.display_name, + "price_unit": cost.price_unit, + "account_id": account.id, + "fsm_order_ids": [(4, self.id)], + "tax_ids": [(6, 0, tax_ids.ids)], + }, + ) + ) vals = { "partner_id": self.person_id.partner_id.id, "type": "in_invoice", "journal_id": jrnl.id or False, "fiscal_position_id": fpos.id or False, "fsm_order_ids": [(4, self.id)], - "company_id": self.env.user.company_id.id, + "company_id": self.env.company.id, + "invoice_line_ids": invoice_line_vals, } - bill = self.env["account.invoice"].sudo().create(vals) - for line in self.contractor_cost_ids: - line.invoice_id = bill - bill.compute_taxes() + bill = self.env["account.move"].sudo().create(vals) + bill._recompute_tax_lines() def account_confirm(self): for order in self: - contractor = order.person_id.partner_id.supplier + contractor = order.person_id.partner_id.supplier_rank if order.contractor_cost_ids: if contractor: order.create_bills() @@ -121,7 +145,7 @@ def account_confirm(self): def account_create_invoice(self): jrnl = self.env["account.journal"].search( [ - ("company_id", "=", self.env.user.company_id.id), + ("company_id", "=", self.env.company.id), ("type", "=", "sale"), ("active", "=", True), ], @@ -131,76 +155,91 @@ def account_create_invoice(self): if not self.customer_id: raise ValidationError(_("Contact empty")) fpos = self.customer_id.property_account_position_id - vals = { + invoice_vals = { "partner_id": self.customer_id.id, "type": "out_invoice", "journal_id": jrnl.id or False, "fiscal_position_id": fpos.id or False, "fsm_order_ids": [(4, self.id)], } - invoice = self.env["account.invoice"].sudo().create(vals) - price_list = invoice.partner_id.property_product_pricelist + price_list = self.customer_id.property_product_pricelist + else: fpos = self.location_id.customer_id.property_account_position_id - vals = { + invoice_vals = { "partner_id": self.location_id.customer_id.id, "type": "out_invoice", "journal_id": jrnl.id or False, "fiscal_position_id": fpos.id or False, "fsm_order_ids": [(4, self.id)], - "company_id": self.env.user.company_id.id, + "company_id": self.env.company.id, } - invoice = self.env["account.invoice"].sudo().create(vals) - price_list = invoice.partner_id.property_product_pricelist + price_list = self.location_id.customer_id.property_product_pricelist + + invoice_line_vals = [] for cost in self.contractor_cost_ids: price = price_list.get_product_price( product=cost.product_id, quantity=cost.quantity, - partner=invoice.partner_id, + partner=invoice_vals.get("partner_id"), date=False, uom_id=False, ) template = cost.product_id.product_tmpl_id accounts = template.get_product_accounts() account = accounts["income"] - vals = { - "product_id": cost.product_id.id, - "account_analytic_id": cost.account_analytic_id.id, - "quantity": cost.quantity, - "name": cost.name, - "price_unit": price, - "account_id": account.id, - "invoice_id": invoice.id, - "fsm_order_id": self.id, - } - con_cost = self.env["account.invoice.line"].create(vals) taxes = template.taxes_id - con_cost.invoice_line_tax_ids = fpos.map_tax(taxes) + tax_ids = fpos.map_tax(taxes) + invoice_line_vals.append( + ( + 0, + 0, + { + "product_id": cost.product_id.id, + "analytic_account_id": self.location_id.analytic_account_id.id, + "quantity": cost.quantity, + "name": cost.product_id.display_name, + "price_unit": price, + "account_id": account.id, + "fsm_order_ids": [(4, self.id)], + "tax_ids": [(6, 0, tax_ids.ids)], + }, + ) + ) for line in self.employee_timesheet_ids: price = price_list.get_product_price( product=line.product_id, quantity=line.unit_amount, - partner=invoice.partner_id, + partner=invoice_vals.get("partner_id"), date=False, uom_id=False, ) template = line.product_id.product_tmpl_id accounts = template.get_product_accounts() account = accounts["income"] - vals = { - "product_id": line.product_id.id, - "account_analytic_id": line.account_id.id, - "quantity": line.unit_amount, - "name": line.name, - "price_unit": price, - "account_id": account.id, - "invoice_id": invoice.id, - "fsm_order_id": self.id, - } - time_cost = self.env["account.invoice.line"].create(vals) taxes = template.taxes_id - time_cost.invoice_line_tax_ids = fpos.map_tax(taxes) - invoice.compute_taxes() + tax_ids = fpos.map_tax(taxes) + invoice_line_vals.append( + ( + 0, + 0, + { + "product_id": line.product_id.id, + "analytic_account_id": line.account_id.id, + "quantity": line.unit_amount, + "name": line.name, + "price_unit": price, + "account_id": account.id, + "fsm_order_ids": [(4, self.id)], + "tax_ids": [(6, 0, tax_ids.ids)], + }, + ) + ) + + invoice_vals.update({"invoice_line_ids": invoice_line_vals}) + invoice = self.env["account.move"].sudo().create(invoice_vals) + + invoice._recompute_tax_lines() self.account_stage = "invoiced" return invoice diff --git a/fieldservice_isp_account/models/fsm_order_cost.py b/fieldservice_isp_account/models/fsm_order_cost.py new file mode 100644 index 0000000000..1eff39731e --- /dev/null +++ b/fieldservice_isp_account/models/fsm_order_cost.py @@ -0,0 +1,24 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class FsmOrderCost(models.Model): + + _name = "fsm.order.cost" + _description = "Fsm Order Cost" + + fsm_order_id = fields.Many2one(comodel_name="fsm.order", required=True,) + price_unit = fields.Float(string="Unit Price", required=True,) + quantity = fields.Float(string="Quantity", required=True, default=1,) + product_id = fields.Many2one( + comodel_name="product.product", string="Product", required=True, + ) + + @api.onchange("product_id") + def onchange_product_id(self): + for cost in self: + if not cost.product_id: + continue + cost.price_unit = cost.product_id.standard_price diff --git a/fieldservice_isp_account/models/fsm_person.py b/fieldservice_isp_account/models/fsm_person.py index 49ea2a9cc7..d88787a80a 100644 --- a/fieldservice_isp_account/models/fsm_person.py +++ b/fieldservice_isp_account/models/fsm_person.py @@ -1,7 +1,7 @@ # Copyright (C) 2018 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import fields, models class FSMPerson(models.Model): @@ -10,19 +10,18 @@ class FSMPerson(models.Model): bill_count = fields.Integer(string="Vendor Bills", compute="_compute_vendor_bills") def _compute_vendor_bills(self): - self.bill_count = self.env["account.invoice"].search_count( + self.bill_count = self.env["account.move"].search_count( [("partner_id", "=", self.partner_id.id)] ) - @api.multi def action_view_bills(self): for bill in self: action = self.env.ref("account.action_invoice_tree1").read()[0] - vendor_bills = self.env["account.invoice"].search( + vendor_bills = self.env["account.move"].search( [("partner_id", "=", bill.partner_id.id)] ) if len(vendor_bills) == 1: - action["views"] = [(self.env.ref("account.invoice_form").id, "form")] + action["views"] = [(self.env.ref("account.view_move_form").id, "form")] action["res_id"] = vendor_bills.id else: action["domain"] = [("id", "in", vendor_bills.ids)] diff --git a/fieldservice_isp_account/security/fsm_order_cost.xml b/fieldservice_isp_account/security/fsm_order_cost.xml new file mode 100644 index 0000000000..e8d0ef7fcb --- /dev/null +++ b/fieldservice_isp_account/security/fsm_order_cost.xml @@ -0,0 +1,23 @@ + + + + + fsm.order.cost access base user + + + + + + + + + fsm.order.cost access fieldservice user + + + + + + + + diff --git a/fieldservice_isp_account/static/description/index.html b/fieldservice_isp_account/static/description/index.html index 04cc1226d9..1dab785e80 100644 --- a/fieldservice_isp_account/static/description/index.html +++ b/fieldservice_isp_account/static/description/index.html @@ -367,7 +367,7 @@

Field Service - ISP Accounting

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/field-service Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/field-service Translate me on Weblate Try me on Runbot

This module adds the ability to track employee time and contractor costs for Field Service Orders. It also adds functionality to create a customer invoice and a vendor bill when a Field Service Order is @@ -413,7 +413,7 @@

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -448,7 +448,7 @@

Maintainers

promote its widespread use.

Current maintainers:

osimallen brian10048 bodedra

-

This module is part of the OCA/field-service project on GitHub.

+

This module is part of the OCA/field-service project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/fieldservice_isp_account/tests/test_isp_account.py b/fieldservice_isp_account/tests/test_isp_account.py index 8347ca24a8..cf600c26ac 100644 --- a/fieldservice_isp_account/tests/test_isp_account.py +++ b/fieldservice_isp_account/tests/test_isp_account.py @@ -3,27 +3,42 @@ from odoo import fields from odoo.exceptions import ValidationError +from odoo.tests import SavepointCase -from odoo.addons.fieldservice_account.tests.test_fsm_account import FSMAccountCase - -class FSMAccountCase(FSMAccountCase): - def setUp(self): - super(FSMAccountCase, self).setUp() - self.test_person = self.env["fsm.person"].create({"name": "Worker-1"}) - self.test_analytic = self.env.ref("analytic.analytic_administratif") - self.account_id = self.env["account.account"].create( +class FSMISPAccountCase(SavepointCase): + @classmethod + def setUpClass(cls): + super(FSMISPAccountCase, cls).setUpClass() + cls.AccountMoveLine = cls.env["account.move.line"] + cls.test_person = cls.env["fsm.person"].create({"name": "Worker-1"}) + cls.test_analytic = cls.env.ref("analytic.analytic_administratif") + cls.account_id = cls.env["account.account"].create( { "code": "NC1110", "name": "Test Payable Account", - "user_type_id": self.env.ref("account.data_account_type_payable").id, + "user_type_id": cls.env.ref("account.data_account_type_payable").id, "reconcile": True, } ) + # create a Res Partner to be converted to FSM Location/Person + cls.test_loc_partner = cls.env["res.partner"].create( + {"name": "Test Loc Partner", "phone": "ABC", "email": "tlp@email.com"} + ) + # create expected FSM Location to compare to converted FSM Location + cls.test_location = cls.env["fsm.location"].create( + { + "name": "Test Location", + "phone": "123", + "email": "tp@email.com", + "partner_id": cls.test_loc_partner.id, + "owner_id": cls.test_loc_partner.id, + "customer_id": cls.test_loc_partner.id, + } + ) def _create_workorder(self, bill_to, contractors, timesheets): # Create a new work order - contractors = self.env["account.invoice.line"].create(contractors) timesheets = self.env["account.analytic.line"].create(timesheets) order = self.env["fsm.order"].create( @@ -31,10 +46,13 @@ def _create_workorder(self, bill_to, contractors, timesheets): "location_id": self.test_location.id, "bill_to": bill_to, "person_id": self.test_person.id, - "contractor_cost_ids": [(6, 0, contractors.ids)], "employee_timesheet_ids": [(6, 0, timesheets.ids)], } ) + for contractor in contractors: + contractor.update({"fsm_order_id": order.id}) + contractors = self.env["fsm.order.cost"].create(contractors) + order.write({"contractor_cost_ids": [(6, 0, contractors.ids)]}) order.person_ids += self.test_person return order @@ -47,18 +65,18 @@ def _process_order_to_invoices(self, order): self.assertEqual(order.account_stage, "review") # Create vendor bill # Vendor bill created from order's contractor - if not order.person_id.partner_id.supplier: + if not order.person_id.partner_id.supplier_rank: with self.assertRaises(ValidationError) as e: order.account_confirm() self.assertEqual( e.exception.name, "The worker assigned to this order is not a supplier" ) - order.person_id.partner_id.supplier = True + order.person_id.partner_id.supplier_rank = True order.account_confirm() self.assertEqual(order.account_stage, "confirmed") - bill = self.AccountInvoice.search( - [("type", "=", "in_invoice"), ("fsm_order_id", "=", order.id)] - ) + bill = self.AccountMoveLine.search( + [("fsm_order_ids", "in", order.id)] + ).move_id.filtered(lambda i: i.type == "in_invoice") self.assertEqual(len(bill), 1) self.assertEqual(len(order.contractor_cost_ids), len(bill.invoice_line_ids)) # Customer invoice created from order's contractor and timehsheet @@ -68,9 +86,9 @@ def _process_order_to_invoices(self, order): order.customer_id = self.test_loc_partner # Assign some partner order.account_create_invoice() self.assertEqual(order.account_stage, "invoiced") - invoice = self.AccountInvoice.search( - [("type", "=", "out_invoice"), ("fsm_order_id", "=", order.id)] - ) + invoice = self.AccountMoveLine.search( + [("fsm_order_ids", "in", order.id)] + ).move_id.filtered(lambda i: i.type == "out_invoice") self.assertEqual(len(invoice), 1) self.assertEqual( len(order.contractor_cost_ids) + len(order.employee_timesheet_ids), @@ -113,9 +131,7 @@ def test_fsm_order_bill_to_location(self): self.test_location.analytic_account_id = self.test_analytic contractors = [ { - "name": "contractor_line_1", "product_id": self.env.ref("product.expense_hotel").id, - "account_id": self.account_id.id, "quantity": 2, "price_unit": 200, }, @@ -146,10 +162,9 @@ def test_fsm_order_bill_to_location(self): self.assertEqual(order.contractor_total, 400) self.assertEqual(order.employee_time_total, 10) # Hrs self.assertEqual(order.total_cost, 1400) - # Testing not working "Need to Configure Chart of Accounts" - # bill, invoice = self._process_order_to_invoices(order) - # self.assertEqual(bill.partner_id, order.person_id.partner_id) - # self.assertEqual(invoice.partner_id, order.location_id.customer_id) + bill, invoice = self._process_order_to_invoices(order) + self.assertEqual(bill.partner_id, order.person_id.partner_id) + self.assertEqual(invoice.partner_id, order.location_id.customer_id) def test_fsm_order_bill_to_contact(self): """Bill To Contact, @@ -160,16 +175,12 @@ def test_fsm_order_bill_to_contact(self): # Create a new work order with contract = 500 and timesheet = 300 contractors = [ { - "name": "contractor_line_2", "product_id": self.env.ref("product.expense_hotel").id, - "account_id": self.account_id.id, "quantity": 2, "price_unit": 100, }, { - "name": "contractor_line_3", "product_id": self.env.ref("product.expense_hotel").id, - "account_id": self.account_id.id, "quantity": 1, "price_unit": 300, }, diff --git a/fieldservice_isp_account/views/account.xml b/fieldservice_isp_account/views/account.xml index 20ab239899..d9fd69d762 100644 --- a/fieldservice_isp_account/views/account.xml +++ b/fieldservice_isp_account/views/account.xml @@ -3,7 +3,6 @@ Service Orders fsm.order - form tree,form diff --git a/fieldservice_isp_account/views/fsm_order.xml b/fieldservice_isp_account/views/fsm_order.xml index 2563e4e60c..1625294076 100644 --- a/fieldservice_isp_account/views/fsm_order.xml +++ b/fieldservice_isp_account/views/fsm_order.xml @@ -42,20 +42,9 @@ - - - - - - - + + + @@ -90,6 +79,11 @@ /> +