Merge pull request #183 from EBII/10-new-quick-bom

[MIG 10] Product quick bom
This commit is contained in:
Lois Rilo
2017-11-09 15:32:29 +01:00
committed by GitHub
12 changed files with 382 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=================
Product Quick Bom
=================
This module was written to create quickly the bom for your product.
Indeed in the product form you now have a new tab "bom" that give you the posibility
to add the bom line directly here
Usage
=====
To use this module, you need to:
* Go to a product form, click on edit, add a line in the bom tab and see that a bom
linked to the product have been created.
.. 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
.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "8.0" for example
For further information, please visit:
* https://www.odoo.com/forum/help-1
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
=======
Contributors
------------
* Sébastien Beau <sebastien.beau@aketion.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 http://odoo-community.org.

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2015 Akretion (http://www.akretion.com).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

View File

@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2015 Akretion (http://www.akretion.com).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Product Quick Bom",
"summary": "Create the bom directly from the product",
"version": "10.0.1.0.0",
"category": "mrp",
"website": "https://odoo-community.org/",
"author": "Akretion, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"mrp",
],
"data": [
"views/product_view.xml",
],
}

View File

@@ -0,0 +1,42 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_quick_bom
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-09-13 16:24+0000\n"
"PO-Revision-Date: 2015-09-13 16:24+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: product_quick_bom
#: model:ir.model,name:product_quick_bom.model_mrp_bom
msgid "Bill of Material"
msgstr "Nomenclature"
#. module: product_quick_bom
#: field:product.template,bom_line_ids:0
msgid "Bom Line"
msgstr "Composant"
#. module: product_quick_bom
#: view:product.template:product_quick_bom.product_template_form_view
msgid "Bom line"
msgstr "Composant"
#. module: product_quick_bom
#: help:product.template,bom_line_ids:0
msgid "If your product is manufactured you can select here the component to produce them"
msgstr "Si votre produit est fabriqué vous pouvez définir les composants ici"
#. module: product_quick_bom
#: model:ir.model,name:product_quick_bom.model_product_template
msgid "Product Template"
msgstr "Modèle d'article"

View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2015 Akretion (http://www.akretion.com).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import product
from . import bom

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2015 Akretion (http://www.akretion.com).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models, _
class MrpBom(models.Model):
_inherit = 'mrp.bom'
_sql_constraint = (
'uniq_product_template',
'uniq(product_tmpl_id)',
_('You can only have one Bom per product template'),
)
class MrpBomLine(models.Model):
_inherit = 'mrp.bom.line'
product_tmpl_id = fields.Many2one(
comodel_name='product.template',
related='bom_id.product_tmpl_id',
readonly=True,
store=True)

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2015 Akretion (http://www.akretion.com).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
bom_line_ids = fields.One2many(
comodel_name='mrp.bom.line',
inverse_name='product_tmpl_id',
string='Bom Line',
help='If your product is manufactured you can select '
'here the component to produce them')
@api.model
def _extract_bom_line(self, vals):
return vals.pop('bom_line_ids', {})
@api.multi
def _prepare_bom_vals(self, vals):
self.ensure_one()
return {
'product_tmpl_id': self.id,
'bom_line_ids': vals,
}
@api.multi
def _process_bom_vals(self, vals):
for record in self:
if record.bom_ids:
record.bom_ids[0].write({'bom_line_ids': vals})
else:
record.env['mrp.bom'].create(self._prepare_bom_vals(vals))
@api.model
def create(self, vals):
bom_vals = self._extract_bom_line(vals)
record = super(ProductTemplate, self).create(vals)
if bom_vals:
record._process_bom_vals(bom_vals)
return record
@api.multi
def write(self, vals):
""" default_type is in product and bom so _context ovewrite the default
value for bom with typ:'product' need to becarefull
"""
bom_vals = self._extract_bom_line(vals)
res = super(ProductTemplate, self).write(vals)
if bom_vals:
ctx = self._context.copy()
ctx.pop('default_type', None)
self.with_context(ctx)._process_bom_vals(bom_vals)
return res
@api.multi
def unlink(self):
for record in self:
if record.bom_ids:
record.bom_ids.unlink()
return super(ProductTemplate, self).unlink()

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 45 KiB

View File

@@ -0,0 +1 @@
from . import test_quick_bom

View File

@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2015 Akretion (http://www.akretion.com).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
import logging
_logger = logging.getLogger(__name__)
class TestQuickBom(TransactionCase):
def setUp(self):
super(TestQuickBom, self).setUp()
self.computer = self.env.ref(
'product.product_product_5_product_template')
self.ram = self.env.ref('product.product_product_13_product_template')
self.hard_drive = self.env.ref(
'product.product_product_17_product_template')
self.cpu = self.env.ref('product.product_product_22_product_template')
def test_create_bom(self):
self.computer.write({'bom_line_ids': [
(0, 0, {'product_id': self.ram.id, 'product_qty': 2, }),
(0, 0, {'product_id': self.hard_drive.id, 'product_qty': 2, }),
(0, 0, {'product_id': self.cpu.id, 'product_qty': 1, })]})
bom = self.computer.bom_ids
self.assertEqual(self.computer.id, bom.product_tmpl_id.id)
self.assertEqual(bom.bom_line_ids[0].product_id.id, self.ram.id)
self.assertEqual(bom.bom_line_ids[0].product_qty, 2)
self.assertEqual(bom.bom_line_ids[1].product_id.id, self.hard_drive.id)
self.assertEqual(bom.bom_line_ids[1].product_qty, 2)
self.assertEqual(bom.bom_line_ids[2].product_id.id, self.cpu.id)
self.assertEqual(bom.bom_line_ids[2].product_qty, 1)
def test_read_bom(self):
bom = self.env['mrp.bom'].create({
'type': 'normal',
'product_tmpl_id': self.computer.id})
bomline1 = self.env['mrp.bom.line'].create({
'product_id': self.ram.id,
'product_qty': 2,
'bom_id': bom.id,
})
bomline2 = self.env['mrp.bom.line'].create({
'product_id': self.hard_drive.id,
'product_qty': 2,
'bom_id': bom.id,
})
bomline3 = self.env['mrp.bom.line'].create({
'product_id': self.cpu.id,
'product_qty': 1,
'bom_id': bom.id,
})
self.assertTrue(bomline1 in self.computer.bom_line_ids)
self.assertTrue(bomline2 in self.computer.bom_line_ids)
self.assertTrue(bomline3 in self.computer.bom_line_ids)

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="product_template_form_view" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="priority" eval="200"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='sales']" position="after">
<page name="bom_line" string="Bom line">
<field name="bom_line_ids">
<tree editable="bottom">
<field name="product_id"/>
<field name="product_qty"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>
</odoo>