diff --git a/subcontracted_service/README.rst b/subcontracted_service/README.rst index f770903425a..300fbd1444f 100644 --- a/subcontracted_service/README.rst +++ b/subcontracted_service/README.rst @@ -1,14 +1,24 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 -======================================= -Trigger procurement for service product -======================================= +====================== +Subcontracted services +====================== -This module adds the functionality of being able to create a procurement -which contains service products. This is the case of subcontracted services, -as for instance assemblies. +This module allows a user to indicate that a service is subcontracted. +It provides the ability to create purchases from procurement processes. + +This is a base module, upon specific modules for sale / manufacuturing, modules +will need to rely on. By itself it does not provide any function to the end user. + +Possible uses of this module can be: + +* Add subcontracted services to BOMs. When a manufacturing order is created a + PO is triggered for the service to be subcontracted. See + +* Add subcontracted services to sales order. When the SO is confirmed, it + creates a PO for the service. Configuration @@ -28,13 +38,9 @@ To configure this module, you need to: Usage ===== -To use this module, you need to: - -#. Create a procurement order of a subcontracted service product. - .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/142/10.0 + :target: https://runbot.odoo-community.org/runbot/142/11.0 Bug Tracker @@ -51,7 +57,7 @@ Credits Images ------ -* Odoo Community Association: `Icon `_. +* Odoo Community Association: `Icon `_. Contributors ------------ diff --git a/subcontracted_service/__init__.py b/subcontracted_service/__init__.py index 84cd7a34b33..01f782dd743 100644 --- a/subcontracted_service/__init__.py +++ b/subcontracted_service/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from . import models from .init_hook import post_init_hook diff --git a/subcontracted_service/__manifest__.py b/subcontracted_service/__manifest__.py index 49d66df4568..afc58f7cb0a 100644 --- a/subcontracted_service/__manifest__.py +++ b/subcontracted_service/__manifest__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Author: Damien Crier # Copyright 2017 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -6,7 +5,7 @@ { "name": 'Subcontracted service', "summary": 'Subcontracted service', - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "category": "Purchase", "website": "https://odoo-community.org/", "author": "Camptocamp, Odoo Community Association (OCA)", diff --git a/subcontracted_service/init_hook.py b/subcontracted_service/init_hook.py index 6b253050fe6..6b57af64f3e 100644 --- a/subcontracted_service/init_hook.py +++ b/subcontracted_service/init_hook.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Author: Damien Crier # Copyright 2017 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/subcontracted_service/models/__init__.py b/subcontracted_service/models/__init__.py index 3e054e497c5..0e5749b9d59 100644 --- a/subcontracted_service/models/__init__.py +++ b/subcontracted_service/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from . import product from . import procurement diff --git a/subcontracted_service/models/procurement.py b/subcontracted_service/models/procurement.py index 1c401dbaecb..13dd605ab61 100644 --- a/subcontracted_service/models/procurement.py +++ b/subcontracted_service/models/procurement.py @@ -1,36 +1,26 @@ -# -*- coding: utf-8 -*- -# Author: Damien Crier -# Copyright 2017 Camptocamp SA -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - +# # Author: Damien Crier +# # Copyright 2017 Camptocamp SA +# # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# from odoo import api, models -class ProcurementOrder(models.Model): - _inherit = "procurement.order" +class ProcurementGroup(models.Model): + _inherit = "procurement.group" - @api.multi - def _is_subcontracted_service(self): - self.ensure_one() - return (self.product_id.type == 'service' and - self.product_id.property_subcontracted_service or + @api.model + def _is_subcontracted_service(self, product_id): + return (product_id.type == 'service' and + product_id.property_subcontracted_service or False) - @api.multi - def _find_suitable_rule(self): - res = super(ProcurementOrder, self)._find_suitable_rule() - if self._is_subcontracted_service(): - return ( - self.warehouse_id.subcontracting_service_proc_rule_id.id - ) - return res - - @api.multi - def _assign(self): - res = super(ProcurementOrder, self)._assign() + @api.model + def _get_rule(self, product_id, location_id, values): + res = super()._get_rule(product_id, location_id, values) if not res: - rule_id = self._find_suitable_rule() - if rule_id: - self.write({'rule_id': rule_id}) - return True + if self._is_subcontracted_service(product_id): + rule_id = location_id.get_warehouse().\ + subcontracting_service_proc_rule_id + if rule_id: + return rule_id return res diff --git a/subcontracted_service/models/product.py b/subcontracted_service/models/product.py index 13bcf01fbcf..30a7462ef0d 100644 --- a/subcontracted_service/models/product.py +++ b/subcontracted_service/models/product.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- # Author: Damien Crier # Copyright 2017 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import api, fields, models +from odoo import fields, models class ProductTemplate(models.Model): @@ -12,15 +11,3 @@ class ProductTemplate(models.Model): property_subcontracted_service = fields.Boolean( string="Subcontracted Service", company_dependent=True) - - -class ProductProduct(models.Model): - _inherit = 'product.product' - - @api.multi - def _need_procurement(self): - for product in self: - if (product.type == 'service' and - product.property_subcontracted_service): - return True - return super(ProductProduct, self)._need_procurement() diff --git a/subcontracted_service/models/warehouse.py b/subcontracted_service/models/warehouse.py index 4844e31a2a5..28f0251e0be 100644 --- a/subcontracted_service/models/warehouse.py +++ b/subcontracted_service/models/warehouse.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 Eficent Business and IT Consulting Services S.L. # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). @@ -14,6 +13,10 @@ class StockWarehouse(models.Model): string="Subcontracting Service Procurement Rule" ) + def _get_buy_route(self): + return self.env.ref('purchase.route_warehouse0_buy', + raise_if_not_found=False).id + @api.multi def _get_vals_for_proc_rule_subcontracting(self): self.ensure_one() @@ -27,6 +30,7 @@ def _get_vals_for_proc_rule_subcontracting(self): 'company_id': self.company_id.id, 'action': 'buy', 'picking_type_id': picking_type.id, + 'route_id': self._get_buy_route(), } @api.multi diff --git a/subcontracted_service/tests/__init__.py b/subcontracted_service/tests/__init__.py index c1bd172a62f..b1779e6d848 100644 --- a/subcontracted_service/tests/__init__.py +++ b/subcontracted_service/tests/__init__.py @@ -1,3 +1,2 @@ -# -*- coding: utf-8 -*- from . import test_subcontracted_service diff --git a/subcontracted_service/tests/test_subcontracted_service.py b/subcontracted_service/tests/test_subcontracted_service.py index 438c587b0c2..565fd93d957 100644 --- a/subcontracted_service/tests/test_subcontracted_service.py +++ b/subcontracted_service/tests/test_subcontracted_service.py @@ -1,15 +1,15 @@ -# -*- coding: utf-8 -*- # Author: Damien Crier # Copyright 2017 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo.tests.common import TransactionCase +from odoo import fields class TestSubcontractedService(TransactionCase): def setUp(self): super(TestSubcontractedService, self).setUp() - self.procurement_obj = self.env['procurement.order'] + self.procurement_group_obj = self.env['procurement.group'] self.obj_warehouse = self.env['stock.warehouse'] # 1. find a supplier @@ -50,14 +50,24 @@ def test_subcontracted_service_procurement(self): """Test if the subcontracting service procurement rule is correctly assigned when creating a procurement for a subcontracted service product.""" + values = { + 'warehouse_id': self.test_wh, + 'company_id': self.test_wh.company_id, + 'date_planned': fields.Date.today(), + 'group_id': self.test_wh. + subcontracting_service_proc_rule_id.group_id, + } self.pdt_service.property_subcontracted_service = True - proc = self.procurement_obj.create({ - 'name': 'Test procurement', - 'product_id': self.pdt_service.id, - 'product_qty': 1.0, - 'product_uom': self.pdt_service.uom_id.id, - 'warehouse_id': self.test_wh.id - }) - self.assertEqual( - proc.rule_id, self.test_wh.subcontracting_service_proc_rule_id, - 'Procurement Rule assigned incorrectly.') + self.procurement_group_obj.run( + self.pdt_service, 1, + self.pdt_service.uom_id, + self.test_wh.lot_stock_id, 'test', 'test', values) + po_line = self.env['purchase.order.line'].search( + [('product_id', '=', self.pdt_service.id)], limit=1) + self.assertEqual(len(po_line), 1) + self.assertEqual(po_line.product_qty, 1) + self.assertEqual(po_line.product_uom, self.pdt_service.uom_id) + self.assertEqual(po_line.order_id.group_id, + self.test_wh. + subcontracting_service_proc_rule_id.group_id) + self.assertEqual(po_line.company_id, self.test_wh.company_id) diff --git a/subcontracted_service/views/product_template.xml b/subcontracted_service/views/product_template.xml index 08895f55945..36e52df16cb 100644 --- a/subcontracted_service/views/product_template.xml +++ b/subcontracted_service/views/product_template.xml @@ -1,4 +1,4 @@ - + @@ -12,4 +12,4 @@ - \ No newline at end of file +