From 63d9a69d3c4ada79a678455a7de3ac60621b2afc Mon Sep 17 00:00:00 2001 From: Vimal Patel Date: Tue, 29 Jun 2021 18:06:01 +0530 Subject: [PATCH] [14.0][MIG]fieldservice_stock_account_analytic: migrated to v14 --- .../__manifest__.py | 29 +++++---- .../models/__init__.py | 2 +- .../models/fsm_order.py | 18 +++--- .../models/stock_request.py | 15 +++-- .../tests/__init__.py | 4 ++ .../tests/test_fsm_stock_account_analytic.py | 60 +++++++++++++++++++ 6 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 fieldservice_stock_account_analytic/tests/__init__.py create mode 100644 fieldservice_stock_account_analytic/tests/test_fsm_stock_account_analytic.py diff --git a/fieldservice_stock_account_analytic/__manifest__.py b/fieldservice_stock_account_analytic/__manifest__.py index 8c8fb5347d..c38ac603e2 100644 --- a/fieldservice_stock_account_analytic/__manifest__.py +++ b/fieldservice_stock_account_analytic/__manifest__.py @@ -1,20 +1,19 @@ -# Copyright (C) 2019 Open Source Integrators +# Copyright (C) 2021 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Field Service - Stock - Analytic Accounting', - 'summary': 'Track costs of delivered items with analytic accounting', - 'license': 'AGPL-3', - 'version': '12.0.1.1.0', - 'category': 'Field Service', - 'author': "Open Source Integrators, " - "Odoo Community Association (OCA)", - 'website': 'https://github.com/OCA/field-service', - 'depends': [ - 'fieldservice_account_analytic', - 'fieldservice_stock_account', - 'stock_request_analytic', + "name": "Field Service - Stock - Analytic Accounting", + "summary": "Track costs of delivered items with analytic accounting", + "license": "AGPL-3", + "version": "14.0.1.0.0", + "category": "Field Service", + "author": "Open Source Integrators, " "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/field-service", + "depends": [ + "fieldservice_account_analytic", + "fieldservice_stock_account", + "stock_request_analytic", ], - 'development_status': 'Beta', - 'maintainers': ['max3903'], + "development_status": "Beta", + "maintainers": ["max3903"], } diff --git a/fieldservice_stock_account_analytic/models/__init__.py b/fieldservice_stock_account_analytic/models/__init__.py index 492b6b9f30..7d2d28e818 100644 --- a/fieldservice_stock_account_analytic/models/__init__.py +++ b/fieldservice_stock_account_analytic/models/__init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2019 Open Source Integrators +# Copyright (C) 2021 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import stock_request diff --git a/fieldservice_stock_account_analytic/models/fsm_order.py b/fieldservice_stock_account_analytic/models/fsm_order.py index b57c594476..4c78603199 100644 --- a/fieldservice_stock_account_analytic/models/fsm_order.py +++ b/fieldservice_stock_account_analytic/models/fsm_order.py @@ -1,17 +1,17 @@ -# Copyright (C) 2019 Open Source Integrators +# Copyright (C) 2021 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models class FSMOrder(models.Model): - _inherit = 'fsm.order' + _inherit = "fsm.order" - def _prepare_inv_line_for_stock_request(self, stock_request, - invoice=False): - vals = super()._prepare_inv_line_for_stock_request( - stock_request, invoice) - vals.update({ - 'analytic_account_id': self.location_id.analytic_account_id.id, - }) + def _prepare_inv_line_for_stock_request(self, stock_request, invoice=False): + vals = super()._prepare_inv_line_for_stock_request(stock_request, invoice) + vals.update( + { + "analytic_account_id": self.location_id.analytic_account_id.id, + } + ) return vals diff --git a/fieldservice_stock_account_analytic/models/stock_request.py b/fieldservice_stock_account_analytic/models/stock_request.py index 86b3a08a98..28a068f632 100644 --- a/fieldservice_stock_account_analytic/models/stock_request.py +++ b/fieldservice_stock_account_analytic/models/stock_request.py @@ -1,18 +1,17 @@ -# Copyright (C) 2019 Open Source Integrators +# Copyright (C) 2021 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, models class StockRequest(models.Model): - _inherit = 'stock.request' + _inherit = "stock.request" @api.model def create(self, vals): - if 'fsm_order_id' in vals and vals.get('fsm_order_id'): - fsm_order = self.env['fsm.order'].browse(vals.get('fsm_order_id')) - vals.update({ - 'analytic_account_id': - fsm_order.location_id.analytic_account_id.id - }) + if vals.get("fsm_order_id"): + fsm_order = self.env["fsm.order"].browse(vals.get("fsm_order_id")) + vals.update( + {"analytic_account_id": fsm_order.location_id.analytic_account_id.id} + ) return super().create(vals) diff --git a/fieldservice_stock_account_analytic/tests/__init__.py b/fieldservice_stock_account_analytic/tests/__init__.py new file mode 100644 index 0000000000..29c8f1c684 --- /dev/null +++ b/fieldservice_stock_account_analytic/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2022 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import test_fsm_stock_account_analytic diff --git a/fieldservice_stock_account_analytic/tests/test_fsm_stock_account_analytic.py b/fieldservice_stock_account_analytic/tests/test_fsm_stock_account_analytic.py new file mode 100644 index 0000000000..bbd2c68622 --- /dev/null +++ b/fieldservice_stock_account_analytic/tests/test_fsm_stock_account_analytic.py @@ -0,0 +1,60 @@ +# Copyright (C) 2022 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +import datetime + +from odoo.tests.common import TransactionCase + + +class FSMStockAccountAnalyticCase(TransactionCase): + def setUp(self): + super(FSMStockAccountAnalyticCase, self).setUp() + self.fsm_order = self.env["fsm.order"] + self.test_location = self.env.ref("fieldservice.test_location") + self.inv_location = self.env.ref("stock.stock_location_customers") + self.test_person = self.env.ref("fieldservice.test_person") + self.test_partner = self.env.ref("fieldservice.test_partner") + self.analytic_model = self.env["account.analytic.account"] + self.analytic = self.analytic_model.create({"name": "Test"}) + + def test_fsm_order(self): + self.test_person.partner_id.supplier_rank = 1 + self.test_location.inventory_location_id = self.inv_location.id + self.test_location.analytic_account_id = self.analytic.id + fsm_order = self.fsm_order.create( + {"location_id": self.test_location.id, "person_id": self.test_person.id} + ) + + self.env["stock.picking.type"].create( + { + "name": "Stock Request wh", + "sequence_id": self.env.ref("stock_request.seq_stock_request_order").id, + "code": "stock_request_order", + "sequence_code": "SRO", + "warehouse_id": fsm_order.warehouse_id.id, + } + ) + self.product_1 = self.env["product.product"].create( + { + "name": "Product 1", + "type": "product", + "categ_id": self.env.ref("product.product_category_all").id, + } + ) + SR_1 = self.env["stock.request"].create( + { + "warehouse_id": fsm_order.warehouse_id.id, + "location_id": fsm_order.inventory_location_id.id, + "product_id": self.product_1.id, + "product_uom_qty": 1, + "product_uom_id": self.product_1.uom_id.id, + "fsm_order_id": fsm_order.id, + "direction": "outbound", + "expected_date": datetime.datetime.now(), + "picking_policy": "direct", + } + ) + fsm_order.stock_request_ids = [(6, 0, SR_1.ids)] + fsm_order.action_request_submit() + SR_1.action_confirm() + fsm_order.account_create_invoice()