From ca9ce2b9c842fa7bba1f68a708d669bae5bab8a6 Mon Sep 17 00:00:00 2001 From: Ruben Dario Bravo Date: Tue, 30 Apr 2019 13:28:21 -0400 Subject: [PATCH] [MIG] subcontracted_service: Migration to 12.0 --- subcontracted_service/README.rst | 75 +-- subcontracted_service/__manifest__.py | 5 +- subcontracted_service/models/warehouse.py | 16 +- subcontracted_service/readme/CONFIGURE.rst | 10 + subcontracted_service/readme/CONTRIBUTORS.rst | 4 + subcontracted_service/readme/DESCRIPTION.rst | 13 + .../static/description/index.html | 447 ++++++++++++++++++ .../tests/test_subcontracted_service.py | 31 +- 8 files changed, 563 insertions(+), 38 deletions(-) create mode 100644 subcontracted_service/readme/CONFIGURE.rst create mode 100644 subcontracted_service/readme/CONTRIBUTORS.rst create mode 100644 subcontracted_service/readme/DESCRIPTION.rst create mode 100644 subcontracted_service/static/description/index.html diff --git a/subcontracted_service/README.rst b/subcontracted_service/README.rst index 300fbd1444f..5dff2d04f6e 100644 --- a/subcontracted_service/README.rst +++ b/subcontracted_service/README.rst @@ -1,10 +1,29 @@ -.. 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 - -====================== -Subcontracted services -====================== +===================== +Subcontracted service +===================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| 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 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/12.0/subcontracted_service + :alt: OCA/purchase-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/purchase-workflow-12-0/purchase-workflow-12-0-subcontracted_service + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/142/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| This module allows a user to indicate that a service is subcontracted. It provides the ability to create purchases from procurement processes. @@ -20,6 +39,10 @@ Possible uses of this module can be: * Add subcontracted services to sales order. When the SO is confirmed, it creates a PO for the service. +**Table of contents** + +.. contents:: + :local: Configuration ============= @@ -35,49 +58,45 @@ To configure this module, you need to: warehouse through 'Inventory / Configuration / Warehouse Management / Warehouse'. -Usage -===== - -.. 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/11.0 - - 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 smash it by providing detailed and welcomed feedback. +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 `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* Camptocamp Contributors ------------- +~~~~~~~~~~~~ * Damien Crier * Jordi Ballester Alomar * Lois Rilo +* Rubén Bravo +Maintainers +~~~~~~~~~~~ -Maintainer ----------- +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit https://odoo-community.org. +This module is part of the `OCA/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/subcontracted_service/__manifest__.py b/subcontracted_service/__manifest__.py index dcf7e2fd67b..1aa30c877dd 100644 --- a/subcontracted_service/__manifest__.py +++ b/subcontracted_service/__manifest__.py @@ -1,11 +1,12 @@ # Author: Damien Crier # Copyright 2017 Camptocamp SA +# Copyright 2019 Rubén Bravo # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": 'Subcontracted service', "summary": 'Subcontracted service', - "version": "11.0.1.0.1", + "version": "12.0.1.0.0", "category": "Purchase", "website": "https://odoo-community.org/", "author": "Camptocamp, Odoo Community Association (OCA)", @@ -13,7 +14,7 @@ "application": False, "installable": True, "depends": [ - "purchase", + "purchase_stock", ], "data": [ 'views/product_template.xml', diff --git a/subcontracted_service/models/warehouse.py b/subcontracted_service/models/warehouse.py index fd52bee8507..839ac376b88 100644 --- a/subcontracted_service/models/warehouse.py +++ b/subcontracted_service/models/warehouse.py @@ -1,5 +1,6 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. # (http://www.eficent.com) +# Copyright 2019 Rubén Bravo # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import api, fields, models @@ -9,18 +10,19 @@ class StockWarehouse(models.Model): _inherit = 'stock.warehouse' subcontracting_service_proc_rule_id = fields.Many2one( - comodel_name='procurement.rule', + comodel_name='stock.rule', string="Subcontracting Service Procurement Rule" ) def _get_buy_route(self): - return self.env.ref('purchase.route_warehouse0_buy', + return self.env.ref('purchase_stock.route_warehouse0_buy', raise_if_not_found=False).id @api.multi def _get_vals_for_proc_rule_subcontracting(self): self.ensure_one() picking_type = self.in_type_id + if not picking_type: picking_type = self.env['stock.picking.type'].search( [('code', '=', 'incoming'), @@ -36,16 +38,16 @@ def _get_vals_for_proc_rule_subcontracting(self): 'action': 'buy', 'picking_type_id': picking_type.id, 'route_id': self._get_buy_route(), + 'location_id': picking_type.default_location_dest_id.id, } @api.multi def _set_subcontracting_service_proc_rule(self): for rec in self: - if rec.subcontracting_service_proc_rule_id: - continue - vals = rec._get_vals_for_proc_rule_subcontracting() - rule = self.env['procurement.rule'].create(vals) - rec.subcontracting_service_proc_rule_id = rule.id + if not rec.subcontracting_service_proc_rule_id: + vals = rec._get_vals_for_proc_rule_subcontracting() + rule = self.env['stock.rule'].create(vals) + rec.subcontracting_service_proc_rule_id = rule.id return True @api.model diff --git a/subcontracted_service/readme/CONFIGURE.rst b/subcontracted_service/readme/CONFIGURE.rst new file mode 100644 index 00000000000..90b6cf0dc30 --- /dev/null +++ b/subcontracted_service/readme/CONFIGURE.rst @@ -0,0 +1,10 @@ +To configure this module, you need to: + +#. Configure your service product with the flag + ``property_subcontracted_service`` in product form if this product should + trigger a procurement. +#. Add supplier in your product form. +#. Additionally and despite a predefined rule is created in each warehouse, + you can configure the 'Subcontracting_service procurement rule' for each + warehouse through 'Inventory / Configuration / Warehouse Management / + Warehouse'. diff --git a/subcontracted_service/readme/CONTRIBUTORS.rst b/subcontracted_service/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..e5c511486fa --- /dev/null +++ b/subcontracted_service/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Damien Crier +* Jordi Ballester Alomar +* Lois Rilo +* Rubén Bravo diff --git a/subcontracted_service/readme/DESCRIPTION.rst b/subcontracted_service/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..a60743a5c95 --- /dev/null +++ b/subcontracted_service/readme/DESCRIPTION.rst @@ -0,0 +1,13 @@ +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. diff --git a/subcontracted_service/static/description/index.html b/subcontracted_service/static/description/index.html new file mode 100644 index 00000000000..2ec7f239948 --- /dev/null +++ b/subcontracted_service/static/description/index.html @@ -0,0 +1,447 @@ + + + + + + +Subcontracted service + + + +
+

Subcontracted service

+ + +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runbot

+

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.
  • +
+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Configure your service product with the flag +property_subcontracted_service in product form if this product should +trigger a procurement.
  2. +
  3. Add supplier in your product form.
  4. +
  5. Additionally and despite a predefined rule is created in each warehouse, +you can configure the ‘Subcontracting_service procurement rule’ for each +warehouse through ‘Inventory / Configuration / Warehouse Management / +Warehouse’.
  6. +
+
+
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/purchase-workflow project on GitHub.

+

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

+
+
+
+ + diff --git a/subcontracted_service/tests/test_subcontracted_service.py b/subcontracted_service/tests/test_subcontracted_service.py index 565fd93d957..0dad7148344 100644 --- a/subcontracted_service/tests/test_subcontracted_service.py +++ b/subcontracted_service/tests/test_subcontracted_service.py @@ -61,7 +61,36 @@ def test_subcontracted_service_procurement(self): self.procurement_group_obj.run( self.pdt_service, 1, self.pdt_service.uom_id, - self.test_wh.lot_stock_id, 'test', 'test', values) + 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) + + def test_subcontracted_service_procurement2(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 + self.pdt_service.route_ids = False + 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)