mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
ADD module mrp_request_bom_structure
This commit is contained in:
1
mrp_request_bom_structure/__init__.py
Normal file
1
mrp_request_bom_structure/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
21
mrp_request_bom_structure/__manifest__.py
Normal file
21
mrp_request_bom_structure/__manifest__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# © 2020 David BEAL @ Akretion
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
"name": "MRP Request Bom Structure",
|
||||
"version": "12.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Akretion,"
|
||||
"Odoo Community Association (OCA)",
|
||||
"summary": "Shortcut between Manufacturing Request and Bom report",
|
||||
"website": "https://github.com/OCA/manufacture",
|
||||
"category": "Manufacturing",
|
||||
"depends": [
|
||||
"mrp_production_request",
|
||||
],
|
||||
"data": [
|
||||
"data/config_parameter.xml",
|
||||
"views/mrp_request.xml",
|
||||
],
|
||||
"installable": True
|
||||
}
|
||||
11
mrp_request_bom_structure/data/config_parameter.xml
Normal file
11
mrp_request_bom_structure/data/config_parameter.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
|
||||
|
||||
<record model="ir.config_parameter" id="request_bom_structure">
|
||||
<field name="key">request_bom_structure</field>
|
||||
<field name="value">{}</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
42
mrp_request_bom_structure/i18n/fr.po
Normal file
42
mrp_request_bom_structure/i18n/fr.po
Normal file
@@ -0,0 +1,42 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * mrp_request_bom_structure
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 12.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-12-04 10:35+0000\n"
|
||||
"PO-Revision-Date: 2020-12-04 10:35+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: mrp_request_bom_structure
|
||||
#: model:ir.model,name:mrp_request_bom_structure.model_report_mrp_report_bom_structure
|
||||
msgid "BOM Structure Report"
|
||||
msgstr "Rapport de structure de nomenclature"
|
||||
|
||||
#. module: mrp_request_bom_structure
|
||||
#: model_terms:ir.ui.view,arch_db:mrp_request_bom_structure.view_mrp_production_request_form
|
||||
msgid "Bom Structure"
|
||||
msgstr "Structure de nomenclature"
|
||||
|
||||
#. module: mrp_request_bom_structure
|
||||
#: model_terms:ir.ui.view,arch_db:mrp_request_bom_structure.view_mrp_production_request_form
|
||||
msgid "Go to Bom Structure report"
|
||||
msgstr "Se rendre vers le rapport de Structure de nomenclature"
|
||||
|
||||
#. module: mrp_request_bom_structure
|
||||
#: model:ir.model,name:mrp_request_bom_structure.model_mrp_production_request
|
||||
msgid "Manufacturing Request"
|
||||
msgstr "Demande de fabrication"
|
||||
|
||||
#. module: mrp_request_bom_structure
|
||||
#: code:addons/mrp_request_bom_structure/models/mrp_request.py:26
|
||||
#, python-format
|
||||
msgid "Structure"
|
||||
msgstr "Structure"
|
||||
2
mrp_request_bom_structure/models/__init__.py
Normal file
2
mrp_request_bom_structure/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import mrp_request
|
||||
from . import bom_structure
|
||||
24
mrp_request_bom_structure/models/bom_structure.py
Normal file
24
mrp_request_bom_structure/models/bom_structure.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# © 2020 David BEAL @ Akretion
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import json
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class ReportBomStructure(models.AbstractModel):
|
||||
_inherit = "report.mrp.report_bom_structure"
|
||||
|
||||
@api.model
|
||||
def get_html(self, bom_id=False, searchQty=1, searchVariant=False):
|
||||
"""Set quantity from stored parameter"""
|
||||
IConf = self.env["ir.config_parameter"].sudo()
|
||||
param = IConf.get_param("request_bom_structure")
|
||||
param = json.loads(param)
|
||||
if self.env.context.get("model") == "mrp.production.request" and searchQty == 1:
|
||||
# We don't want used stored quantity when we are in an other situation
|
||||
# to avoid break native behavior
|
||||
searchQty = param.get(str(self.env.context.get("uid"))) or searchQty
|
||||
return super().get_html(
|
||||
bom_id=bom_id, searchQty=searchQty, searchVariant=searchVariant
|
||||
)
|
||||
35
mrp_request_bom_structure/models/mrp_request.py
Normal file
35
mrp_request_bom_structure/models/mrp_request.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# © 2020 David BEAL @ Akretion
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import json
|
||||
|
||||
from odoo import _, models
|
||||
|
||||
|
||||
class MrpProductionRequest(models.Model):
|
||||
_inherit = "mrp.production.request"
|
||||
|
||||
def button_open_structure_report(self):
|
||||
""" - store quantity in parameter
|
||||
- return action client
|
||||
"""
|
||||
self.ensure_one()
|
||||
IConf = self.env["ir.config_parameter"].sudo()
|
||||
try:
|
||||
param = json.loads(IConf.get_param("request_bom_structure")) or {}
|
||||
except Exception:
|
||||
param = {}
|
||||
param[str(self.env.context.get("uid"))] = self.product_qty
|
||||
# bom structure report'll use this stored param
|
||||
IConf.set_param("request_bom_structure", json.dumps(param))
|
||||
return {
|
||||
"name": _("Structure"),
|
||||
"res_model": "report.mrp.report_bom_structure",
|
||||
"context": {
|
||||
"model": "report.mrp.report_bom_structure",
|
||||
"active_id": self.bom_id.id,
|
||||
},
|
||||
"target": "current",
|
||||
"tag": "mrp_bom_report",
|
||||
"type": "ir.actions.client",
|
||||
}
|
||||
1
mrp_request_bom_structure/readme/CONTRIBUTORS.rst
Normal file
1
mrp_request_bom_structure/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1 @@
|
||||
* David Béal <david.beal@akretion.com>
|
||||
1
mrp_request_bom_structure/readme/DESCRIPTION.rst
Normal file
1
mrp_request_bom_structure/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1 @@
|
||||
Add a button in Manufacturing Request to dive into 'BoM Structure & Cost' report with the quantity of the request.
|
||||
2
mrp_request_bom_structure/readme/ROADMAP.rst
Normal file
2
mrp_request_bom_structure/readme/ROADMAP.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
Find a better way to send quantity to report instead of storing data in config
|
||||
Actually given context in ir.actions.client is lost in http stack.
|
||||
5
mrp_request_bom_structure/readme/USAGE.rst
Normal file
5
mrp_request_bom_structure/readme/USAGE.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
To use this module, you need to:
|
||||
|
||||
#. Go to *Manufacturing > Operations > Manufacturing Requests*.
|
||||
#. Put any product quantity on your request
|
||||
#. Click on 'Bom Structure'
|
||||
1
mrp_request_bom_structure/tests/__init__.py
Normal file
1
mrp_request_bom_structure/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_request_structure
|
||||
34
mrp_request_bom_structure/tests/test_request_structure.py
Normal file
34
mrp_request_bom_structure/tests/test_request_structure.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# © 2020 David BEAL @ Akretion
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import json
|
||||
|
||||
from odoo.tests.common import SavepointCase
|
||||
|
||||
|
||||
class TestRequest2Structure(SavepointCase):
|
||||
def setUp(self, *args, **kwargs):
|
||||
super().setUp(*args, **kwargs)
|
||||
product = self.env.ref("mrp.product_product_wood_panel")
|
||||
self.bom = self.env.ref("mrp.mrp_bom_wood_panel")
|
||||
self.request = self.env["mrp.production.request"].create(
|
||||
{
|
||||
"name": "Test",
|
||||
"product_qty": 777.0,
|
||||
"product_id": product.id,
|
||||
"bom_id": self.bom.id,
|
||||
}
|
||||
)
|
||||
|
||||
def test_generate_bom_structure_with_right_qty(self):
|
||||
action = self.request.with_context(uid=2).button_open_structure_report()
|
||||
param = self.env["ir.config_parameter"].get_param("request_bom_structure")
|
||||
param = json.loads(param)
|
||||
assert param == {"2": 777.0}
|
||||
res = (
|
||||
self.env["report.mrp.report_bom_structure"]
|
||||
.with_context(model="mrp.production.request", uid=2)
|
||||
.get_html(bom_id=self.bom.id)
|
||||
)
|
||||
assert res["bom_qty"] == 777.0
|
||||
return action
|
||||
18
mrp_request_bom_structure/views/mrp_request.xml
Normal file
18
mrp_request_bom_structure/views/mrp_request.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
|
||||
<record model="ir.ui.view" id="view_mrp_production_request_form">
|
||||
<field name="model">mrp.production.request</field>
|
||||
<field name="inherit_id" ref="mrp_production_request.view_mrp_production_request_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//header/button[@name='button_cancel']" position="after">
|
||||
<button name="button_open_structure_report" type="object"
|
||||
string="Bom Structure" title="Go to Bom Structure report"
|
||||
attrs="{'invisible': [('product_qty', '=', 0)]}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user