Skip to content

Commit

Permalink
[MIG] subcontracted_service: Migration to 11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HviorForgeFlow authored and skukered committed Apr 29, 2019
1 parent ed6d792 commit 58ad5ed
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 76 deletions.
32 changes: 19 additions & 13 deletions subcontracted_service/README.rst
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -51,7 +57,7 @@ Credits
Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.png>`_.

Contributors
------------
Expand Down
1 change: 0 additions & 1 deletion subcontracted_service/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
from .init_hook import post_init_hook
3 changes: 1 addition & 2 deletions subcontracted_service/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
# Author: Damien Crier
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"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)",
Expand Down
1 change: 0 additions & 1 deletion subcontracted_service/init_hook.py
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
1 change: 0 additions & 1 deletion subcontracted_service/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

from . import product
from . import procurement
Expand Down
46 changes: 18 additions & 28 deletions subcontracted_service/models/procurement.py
Original file line number Diff line number Diff line change
@@ -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
15 changes: 1 addition & 14 deletions subcontracted_service/models/product.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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()
6 changes: 5 additions & 1 deletion subcontracted_service/models/warehouse.py
Original file line number Diff line number Diff line change
@@ -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).
Expand All @@ -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()
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion subcontracted_service/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-

from . import test_subcontracted_service
34 changes: 22 additions & 12 deletions subcontracted_service/tests/test_subcontracted_service.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions subcontracted_service/views/product_template.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="product_template_subcontracted_service_view_form" model="ir.ui.view">
Expand All @@ -12,4 +12,4 @@
</field>
</record>

</odoo>
</odoo>

0 comments on commit 58ad5ed

Please sign in to comment.