[10.0][ADD] mrp_production_service

This commit is contained in:
hveficent
2018-04-16 11:49:27 +02:00
committed by Lois Rilo
parent af968f2141
commit adace6f1d0
8 changed files with 196 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
.. 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
======================
MRP Production Service
======================
This module allows to create procurement orders from manufacturing orders when
a services is included in the Bill of Materials.
This allows users to include additional services that has to be procured as
part of the manufacturing process.
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/129/10.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/manufacture/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.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.png>`_.
Contributors
------------
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Héctor Villarreal Ortega <hector.villarreal@eficent.com>
Maintainer
----------
.. 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.

View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2016 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).
from . import models

View File

@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2016 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).
{
"name": "MRP Production Service",
"summary": "Creates procurement orders from manufacturing orders, for "
"services included in the Bill of Materials",
"version": "10.0.1.0.0",
"author": "Eficent,"
"Odoo Community Association (OCA)",
"website": "https://www.odoo-community.org",
"category": "Warehouse Management",
"depends": ["mrp"],
"license": "AGPL-3",
'installable': True,
'application': False,
}

View File

@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import mrp_production

View File

@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# Copyright 2016 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).
from odoo import api, models
class MrpProduction(models.Model):
_inherit = "mrp.production"
@api.model
def _prepare_service_procurement(self, line, production):
location = production.location_src_id
return {
'name': '%s for %s' % (line.product_id.name, production.name),
'origin': production.origin,
'company_id': production.company_id.id,
'date_planned_start': production.date_planned_start,
'product_id': line.product_id.id,
'product_qty': line.product_qty,
'product_uom': line.product_uom_id.id,
'location_id': location.id,
'warehouse_id': location.get_warehouse().id
}
@api.model
def _create_service_procurement(self, line, production):
data = self._prepare_service_procurement(line, production)
return self.env['procurement.order'].create(data)
@api.multi
def _generate_moves(self):
res = super(MrpProduction, self)._generate_moves()
for production in self:
factor = production.product_uom_id._compute_quantity(
production.product_qty,
production.bom_id.product_uom_id
) / production.bom_id.product_qty
boms, lines = production.bom_id.explode(
production.product_id, factor,
picking_type=production.bom_id.picking_type_id)
for line in lines:
if line[0].product_id.type == 'service':
self._create_service_procurement(line[0], production)
return res

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import test_mrp_production_service

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
# Copyright 2018 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).
from odoo.tests.common import TransactionCase
class TestMrpProductionService(TransactionCase):
def setUp(self):
super(TestMrpProductionService, self).setUp()
# Create products
product_model = self.env['product.product']
self.p1 = product_model.create({'name': '101'})
self.p2 = product_model.create({'name': '201P'})
self.p3 = product_model.create({'name': '202P'})
self.service = product_model.create({'name': 'Assembly Service',
'type': 'service'})
# Create bill of materials
self.bom_model = self.env['mrp.bom']
self.bom = self.bom_model.create({
'product_tmpl_id': self.p1.product_tmpl_id.id,
'product_id': self.p1.id,
'product_qty': 1,
'type': 'normal',
})
# Create bom lines
self.bom_line_model = self.env['mrp.bom.line']
self.bom_line_model.create({
'bom_id': self.bom.id,
'product_id': self.p2.id,
'product_qty': 1,
})
self.bom_line_model.create({
'bom_id': self.bom.id,
'product_id': self.p3.id,
'product_qty': 1,
})
self.bom_line_model.create({
'bom_id': self.bom.id,
'product_id': self.service.id,
'product_qty': 1,
})
def test_produce_bom_with_service(self):
"""Explode bill of material and look for a procurement of a service."""
self.mrp_production_model = self.env['mrp.production']
self.env['mrp.production'].create({
'product_id': self.p1.id,
'product_qty': 1.0,
'product_uom_id': self.p1.uom_id.id,
'bom_id': self.bom.id
})
procurement = self.env['procurement.order'].search(
[('product_id', 'in',
self.bom.bom_line_ids.mapped('product_id.id'))])
self.assertEqual(len(procurement), 1)
self.assertEqual(procurement.product_id.type, 'service')