first commit
This commit is contained in:
commit
cf8bb6ced1
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Python
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
__pycache__/
|
||||
|
||||
# Odoo
|
||||
*.log
|
||||
*.pot
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# IDEs
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
17
README.md
Normal file
17
README.md
Normal file
@ -0,0 +1,17 @@
|
||||
# MRP Components Report
|
||||
|
||||
## Overview
|
||||
This custom Odoo 19 module adds a new "Components Required" report under the **Manufacturing > Reporting** menu. It allows users to view a consolidated list of components needed for Manufacturing Orders on a specific date (or within a selected date range).
|
||||
|
||||
## Key Features
|
||||
- **Wizard Entry Point**: Allows users to filter required components by a custom date range.
|
||||
- **Reporting Views**: Provides robust List and Pivot views for analyzing component demand data.
|
||||
- **Multi-Level Grouping**: Components are pre-grouped by **Work Center** and then by **Parent Product** for clear visibility into production station needs.
|
||||
- **Excel Export**: Native Odoo list views support immediate export to `.xlsx`.
|
||||
- **Custom PDF Generation**: Includes a dedicated "Print PDF" action within the wizard for a neatly formatted printable report.
|
||||
|
||||
## Technical Details
|
||||
This module utilizes a PostgreSQL `VIEW` (`mrp.components.report`) to performantly aggregate data from `mrp_production` (Manufacturing Orders) and `stock_move` (Component requirements). Work Center mapping is derived from standard Odoo routing and workorder relationships, gracefully falling back to the Manufacturing Order's primary Work Center if specific operations are undefined.
|
||||
|
||||
## Author
|
||||
Kipas System Implementation
|
||||
2
__init__.py
Normal file
2
__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from . import report
|
||||
from . import wizard
|
||||
17
__manifest__.py
Normal file
17
__manifest__.py
Normal file
@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
{
|
||||
'name': 'MRP Components Report',
|
||||
'version': '19.0.1.0.0',
|
||||
'category': 'Manufacturing/Manufacturing',
|
||||
'summary': 'Report showing needed components for a certain date grouped by work center and parent product',
|
||||
'depends': ['mrp'],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'report/mrp_components_report_views.xml',
|
||||
'wizard/mrp_components_wizard_views.xml',
|
||||
'report/mrp_components_qweb_report.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
'license': 'LGPL-3',
|
||||
}
|
||||
2
report/__init__.py
Normal file
2
report/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from . import mrp_components_report
|
||||
from . import mrp_components_pdf_report
|
||||
69
report/mrp_components_pdf_report.py
Normal file
69
report/mrp_components_pdf_report.py
Normal file
@ -0,0 +1,69 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, api
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
class ReportMrpComponents(models.AbstractModel):
|
||||
_name = 'report.mrp_components_report.report_mrp_components_template'
|
||||
_description = 'MRP Components PDF Report'
|
||||
|
||||
@api.model
|
||||
def _get_report_values(self, docids, data=None):
|
||||
if not data or not data.get('form'):
|
||||
raise UserError("Form content is missing, this report cannot be printed.")
|
||||
|
||||
date_start = data['form'].get('date_start')
|
||||
date_end = data['form'].get('date_end')
|
||||
|
||||
domain = [
|
||||
('date', '>=', date_start),
|
||||
('date', '<=', date_end)
|
||||
]
|
||||
|
||||
report_records = self.env['mrp.components.report'].search(domain)
|
||||
|
||||
grouped_data = {}
|
||||
|
||||
for record in report_records:
|
||||
wc_name = record.workcenter_id.name or 'No Work Center'
|
||||
prod_name = record.product_id.display_name or 'No Parent Product'
|
||||
|
||||
if wc_name not in grouped_data:
|
||||
grouped_data[wc_name] = {}
|
||||
if prod_name not in grouped_data[wc_name]:
|
||||
grouped_data[wc_name][prod_name] = []
|
||||
|
||||
grouped_data[wc_name][prod_name].append({
|
||||
'component_name': record.component_id.display_name,
|
||||
'qty': record.product_qty,
|
||||
'uom_name': record.product_uom_id.name,
|
||||
'date': record.date,
|
||||
'mo': record.production_id.name,
|
||||
})
|
||||
|
||||
# Optional: consolidate same components if needed.
|
||||
# But showing individual MOs might be better. Let's consolidate if same component in same MO?
|
||||
# Standard reports usually aggregate quantities. Let's aggregate by component within the product.
|
||||
|
||||
aggregated_data = {}
|
||||
for wc, products in grouped_data.items():
|
||||
aggregated_data[wc] = {}
|
||||
for prod, components in products.items():
|
||||
agg_comps = {}
|
||||
for comp in components:
|
||||
key = comp['component_name']
|
||||
if key not in agg_comps:
|
||||
agg_comps[key] = {
|
||||
'component_name': key,
|
||||
'qty': 0.0,
|
||||
'uom_name': comp['uom_name']
|
||||
}
|
||||
agg_comps[key]['qty'] += comp['qty']
|
||||
aggregated_data[wc][prod] = list(agg_comps.values())
|
||||
|
||||
return {
|
||||
'doc_ids': data.get('ids'),
|
||||
'doc_model': 'mrp.components.wizard',
|
||||
'date_start': date_start,
|
||||
'date_end': date_end,
|
||||
'grouped_data': aggregated_data,
|
||||
}
|
||||
58
report/mrp_components_qweb_report.xml
Normal file
58
report/mrp_components_qweb_report.xml
Normal file
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="action_report_mrp_components" model="ir.actions.report">
|
||||
<field name="name">Components Required Report</field>
|
||||
<field name="model">mrp.components.wizard</field>
|
||||
<field name="report_type">qweb-pdf</field>
|
||||
<field name="report_name">mrp_components_report.report_mrp_components_template</field>
|
||||
<field name="report_file">mrp_components_report.report_mrp_components_template</field>
|
||||
<field name="print_report_name">'Components Required - %s to %s' % (object.date_start, object.date_end)</field>
|
||||
<field name="binding_model_id" ref="model_mrp_components_wizard"/>
|
||||
<field name="binding_type">report</field>
|
||||
</record>
|
||||
|
||||
<template id="report_mrp_components_template">
|
||||
<t t-call="web.html_container">
|
||||
<t t-call="web.external_layout">
|
||||
<div class="page">
|
||||
<div class="text-center mt-4 mb-4">
|
||||
<h2>Components Required Report</h2>
|
||||
<p><strong>From:</strong> <span t-esc="date_start"/> <strong>To:</strong> <span t-esc="date_end"/></p>
|
||||
</div>
|
||||
|
||||
<t t-if="not grouped_data">
|
||||
<div class="alert alert-info mt-4">No components needed for the selected period.</div>
|
||||
</t>
|
||||
|
||||
<t t-foreach="grouped_data.keys()" t-as="workcenter">
|
||||
<h4 class="mt-4 pb-2 border-bottom text-primary"><span t-esc="workcenter"/></h4>
|
||||
|
||||
<t t-foreach="grouped_data[workcenter].keys()" t-as="product">
|
||||
<h6 class="mt-3 ml-3 text-muted"><strong>Parent Product:</strong> <span t-esc="product"/></h6>
|
||||
|
||||
<table class="table table-sm table-bordered mt-2 ml-4">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th class="w-50">Component</th>
|
||||
<th class="w-25 text-right">Quantity Needed</th>
|
||||
<th class="w-25">Unit of Measure</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<t t-foreach="grouped_data[workcenter][product]" t-as="comp">
|
||||
<tr>
|
||||
<td><span t-esc="comp['component_name']"/></td>
|
||||
<td class="text-right"><span t-esc="comp['qty']" t-options='{"widget": "float", "precision": 3}'/></td>
|
||||
<td><span t-esc="comp['uom_name']"/></td>
|
||||
</tr>
|
||||
</t>
|
||||
</tbody>
|
||||
</table>
|
||||
</t>
|
||||
<br/>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
</template>
|
||||
</odoo>
|
||||
64
report/mrp_components_report.py
Normal file
64
report/mrp_components_report.py
Normal file
@ -0,0 +1,64 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import tools
|
||||
from odoo import models, fields
|
||||
|
||||
class MrpComponentsReport(models.Model):
|
||||
_name = 'mrp.components.report'
|
||||
_description = 'MRP Components Report'
|
||||
_auto = False
|
||||
|
||||
id = fields.Id(readonly=True)
|
||||
date = fields.Date('Date Needed', readonly=True)
|
||||
production_id = fields.Many2one('mrp.production', 'Manufacturing Order', readonly=True)
|
||||
product_id = fields.Many2one('product.product', 'Parent Product', readonly=True)
|
||||
component_id = fields.Many2one('product.product', 'Component', readonly=True)
|
||||
workcenter_id = fields.Many2one('mrp.workcenter', 'Work Center', readonly=True)
|
||||
product_qty = fields.Float('Quantity Needed', readonly=True)
|
||||
product_uom_id = fields.Many2one('uom.uom', 'Unit of Measure', readonly=True)
|
||||
state = fields.Selection([
|
||||
('draft', 'Draft'),
|
||||
('confirmed', 'Confirmed'),
|
||||
('progress', 'In Progress'),
|
||||
('to_close', 'To Close'),
|
||||
('done', 'Done'),
|
||||
('cancel', 'Cancelled')], string='MO State', readonly=True)
|
||||
|
||||
def _select(self):
|
||||
return """
|
||||
SELECT
|
||||
sm.id AS id,
|
||||
CAST(mp.date_start AS DATE) AS date,
|
||||
mp.id AS production_id,
|
||||
mp.product_id AS product_id,
|
||||
sm.product_id AS component_id,
|
||||
COALESCE(mw.id, (SELECT workcenter_id FROM mrp_workorder WHERE production_id = mp.id ORDER BY id ASC LIMIT 1)) AS workcenter_id,
|
||||
sm.product_uom_qty AS product_qty,
|
||||
sm.product_uom AS product_uom_id,
|
||||
mp.state AS state
|
||||
"""
|
||||
|
||||
def _from(self):
|
||||
return """
|
||||
FROM stock_move sm
|
||||
JOIN mrp_production mp ON sm.raw_material_production_id = mp.id
|
||||
LEFT JOIN mrp_bom_line mbl ON sm.bom_line_id = mbl.id
|
||||
LEFT JOIN mrp_routing_workcenter mrw ON sm.operation_id = mrw.id
|
||||
LEFT JOIN mrp_routing_workcenter mrw_bom ON mbl.operation_id = mrw_bom.id
|
||||
LEFT JOIN mrp_workorder mwo ON sm.workorder_id = mwo.id
|
||||
LEFT JOIN mrp_workcenter mw ON COALESCE(mrw.workcenter_id, mwo.workcenter_id, mrw_bom.workcenter_id) = mw.id
|
||||
"""
|
||||
|
||||
def _where(self):
|
||||
return """
|
||||
WHERE sm.raw_material_production_id IS NOT NULL
|
||||
AND sm.state != 'cancel'
|
||||
AND mp.state != 'cancel'
|
||||
"""
|
||||
|
||||
def init(self):
|
||||
tools.drop_view_if_exists(self.env.cr, self._table)
|
||||
self.env.cr.execute("""CREATE or REPLACE VIEW %s as (
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
)""" % (self._table, self._select(), self._from(), self._where()))
|
||||
51
report/mrp_components_report_views.xml
Normal file
51
report/mrp_components_report_views.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_mrp_components_report_tree" model="ir.ui.view">
|
||||
<field name="name">mrp.components.report.tree</field>
|
||||
<field name="model">mrp.components.report</field>
|
||||
<field name="arch" type="xml">
|
||||
<list string="Components Needed" create="false" edit="false" delete="false">
|
||||
<field name="date" optional="show"/>
|
||||
<field name="workcenter_id" optional="show"/>
|
||||
<field name="product_id" optional="show"/>
|
||||
<field name="production_id" optional="show"/>
|
||||
<field name="component_id"/>
|
||||
<field name="product_qty" sum="Total Quantity"/>
|
||||
<field name="product_uom_id"/>
|
||||
<field name="state" optional="hide"/>
|
||||
</list>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_mrp_components_report_pivot" model="ir.ui.view">
|
||||
<field name="name">mrp.components.report.pivot</field>
|
||||
<field name="model">mrp.components.report</field>
|
||||
<field name="arch" type="xml">
|
||||
<pivot string="Components Needed" disable_linking="True">
|
||||
<field name="workcenter_id" type="row"/>
|
||||
<field name="product_id" type="row"/>
|
||||
<field name="component_id" type="row"/>
|
||||
<field name="product_qty" type="measure"/>
|
||||
</pivot>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_mrp_components_report_search" model="ir.ui.view">
|
||||
<field name="name">mrp.components.report.search</field>
|
||||
<field name="model">mrp.components.report</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Components Needed">
|
||||
<field name="component_id"/>
|
||||
<field name="product_id"/>
|
||||
<field name="workcenter_id"/>
|
||||
<field name="production_id"/>
|
||||
<group>
|
||||
<filter string="Work Center" name="group_by_workcenter" context="{'group_by':'workcenter_id'}"/>
|
||||
<filter string="Parent Product" name="group_by_product" context="{'group_by':'product_id'}"/>
|
||||
<filter string="Component" name="group_by_component" context="{'group_by':'component_id'}"/>
|
||||
<filter string="Date" name="group_by_date" context="{'group_by':'date'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
3
security/ir.model.access.csv
Normal file
3
security/ir.model.access.csv
Normal file
@ -0,0 +1,3 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_mrp_components_report,mrp.components.report,model_mrp_components_report,mrp.group_mrp_user,1,0,0,0
|
||||
access_mrp_components_wizard,mrp.components.wizard,model_mrp_components_wizard,mrp.group_mrp_user,1,1,1,1
|
||||
|
1
wizard/__init__.py
Normal file
1
wizard/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from . import mrp_components_wizard
|
||||
40
wizard/mrp_components_wizard.py
Normal file
40
wizard/mrp_components_wizard.py
Normal file
@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields
|
||||
|
||||
class MrpComponentsWizard(models.TransientModel):
|
||||
_name = 'mrp.components.wizard'
|
||||
_description = 'MRP Components Report Wizard'
|
||||
|
||||
date_start = fields.Date(string='Start Date', required=True, default=fields.Date.context_today)
|
||||
date_end = fields.Date(string='End Date', required=True, default=fields.Date.context_today)
|
||||
|
||||
def action_view_report(self):
|
||||
self.ensure_one()
|
||||
domain = [
|
||||
('date', '>=', self.date_start),
|
||||
('date', '<=', self.date_end)
|
||||
]
|
||||
|
||||
return {
|
||||
'name': 'Components Needed',
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'mrp.components.report',
|
||||
'view_mode': 'list,pivot',
|
||||
'domain': domain,
|
||||
'context': {
|
||||
'search_default_group_by_workcenter': 1,
|
||||
'search_default_group_by_product': 1,
|
||||
}
|
||||
}
|
||||
|
||||
def action_print_pdf(self):
|
||||
self.ensure_one()
|
||||
data = {
|
||||
'ids': self.ids,
|
||||
'model': self._name,
|
||||
'form': {
|
||||
'date_start': self.date_start,
|
||||
'date_end': self.date_end,
|
||||
},
|
||||
}
|
||||
return self.env.ref('mrp_components_report.action_report_mrp_components').report_action(self, data=data)
|
||||
35
wizard/mrp_components_wizard_views.xml
Normal file
35
wizard/mrp_components_wizard_views.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_mrp_components_wizard_form" model="ir.ui.view">
|
||||
<field name="name">mrp.components.wizard.form</field>
|
||||
<field name="model">mrp.components.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Components Needed Report">
|
||||
<group>
|
||||
<group>
|
||||
<field name="date_start"/>
|
||||
<field name="date_end"/>
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="action_view_report" string="View Report" type="object" class="btn-primary"/>
|
||||
<button name="action_print_pdf" string="Print PDF" type="object" class="btn-secondary"/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_mrp_components_wizard" model="ir.actions.act_window">
|
||||
<field name="name">Components Required</field>
|
||||
<field name="res_model">mrp.components.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_mrp_components_report"
|
||||
name="Components Required"
|
||||
parent="mrp.menu_mrp_reporting"
|
||||
action="action_mrp_components_wizard"
|
||||
sequence="20"/>
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue
Block a user