Skip to content

Commit

Permalink
[ADD] mrp_order_report_lot
Browse files Browse the repository at this point in the history
  • Loading branch information
ivantodorovich committed Feb 13, 2025
1 parent 63c31a0 commit 129efeb
Show file tree
Hide file tree
Showing 11 changed files with 634 additions and 0 deletions.
87 changes: 87 additions & 0 deletions mrp_order_report_lot/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
======================================================
Display Component's Lot on the Production Order Report
======================================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2851f3d35f45a835cf5ff50d3544f916fe057d11c56b3e7352d3524b7025b21f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| 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
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture--reporting-lightgray.png?logo=github
:target: https://github.com/OCA/manufacture-reporting/tree/16.0/mrp_order_report_lot
:alt: OCA/manufacture-reporting
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/manufacture-reporting-16-0/manufacture-reporting-16-0-mrp_order_report_lot
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture-reporting&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds a "Lot / SN" column to the MRP order report, and splits
the consumed quantities by Lot for products tracked by lot.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture-reporting/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/manufacture-reporting/issues/new?body=module:%20mrp_order_report_lot%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* `Camptocamp <https://www.camptocamp.com>`_

* Iván Todorovich <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px
:target: https://github.com/ivantodorovich
:alt: ivantodorovich

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ivantodorovich|

This module is part of the `OCA/manufacture-reporting <https://github.com/OCA/manufacture-reporting/tree/16.0/mrp_order_report_lot>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions mrp_order_report_lot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions mrp_order_report_lot/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2025 Camptocamp SA (https://www.camptocamp.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Display Component's Lot on the Production Order Report",
"version": "16.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture-reporting",
"license": "AGPL-3",
"maintainers": ["ivantodorovich"],
"category": "Manufacturing",
"depends": ["mrp"],
"data": ["reports/mrp_order_report.xml"],
}
1 change: 1 addition & 0 deletions mrp_order_report_lot/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_move
24 changes: 24 additions & 0 deletions mrp_order_report_lot/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2025 Camptocamp SA (https://www.camptocamp.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from collections import defaultdict

from odoo import models


class StockMove(models.Model):
_inherit = "stock.move"

def _get_quantity_by_lot(self):
self.ensure_one()

Check warning on line 13 in mrp_order_report_lot/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_order_report_lot/models/stock_move.py#L13

Added line #L13 was not covered by tests
if self.product_id.tracking != "lot":
return {}
quantity_by_lot = defaultdict(float)

Check warning on line 16 in mrp_order_report_lot/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_order_report_lot/models/stock_move.py#L15-L16

Added lines #L15 - L16 were not covered by tests
for move_line in self.move_line_ids:
quantity_by_lot[

Check warning on line 18 in mrp_order_report_lot/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_order_report_lot/models/stock_move.py#L18

Added line #L18 was not covered by tests
move_line.lot_id or False
] += move_line.product_uom_id._compute_quantity(
move_line.qty_done,
self.product_uom,
)
return quantity_by_lot

Check warning on line 24 in mrp_order_report_lot/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_order_report_lot/models/stock_move.py#L24

Added line #L24 was not covered by tests
3 changes: 3 additions & 0 deletions mrp_order_report_lot/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Camptocamp <https://www.camptocamp.com>`_

* Iván Todorovich <[email protected]>
2 changes: 2 additions & 0 deletions mrp_order_report_lot/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module adds a "Lot / SN" column to the MRP order report, and splits
the consumed quantities by Lot for products tracked by lot.
66 changes: 66 additions & 0 deletions mrp_order_report_lot/reports/mrp_order_report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2025 Camptocamp SA (https://www.camptocamp.com).
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>

<template
id="report_mrp_production_components"
inherit_id="mrp.report_mrp_production_components"
>
<!-- Display the column only if there are products tracked with lot/SN -->
<xpath expr="//table/thead" position="before">
<t
t-set="has_lot"
t-value="o.state in ('progress', 'to_close','done') and any(product.tracking in ('lot', 'serial') for product in o.move_raw_ids.product_id)"
/>
</xpath>
<xpath expr="//table/thead/tr/th[1]" position="after">
<th t-if="has_lot" name="lot">Lot / SN</th>
</xpath>
<!--
For products tracked by lot, we also display an 'Lot missing' column if needed
and split the displayed quantities.
For products tracked by SN we simply print the serial numbers
-->
<xpath expr="//table/tbody/tr/td[1]" position="after">
<t t-set="quantity_by_lot" t-value="raw_line._get_quantity_by_lot()" />
<td t-if="has_lot" name="lot">
<t t-if="raw_line.product_id.tracking in ('lot', 'serial')">
<t t-foreach="quantity_by_lot.keys()" t-as="lot">
<div t-if="lot" t-field="lot.name" />
</t>
<t t-if="raw_line.product_id.tracking == 'lot'">
<div t-if="False in quantity_by_lot">
<span class="fst-italic"><t>Lot missing</t></span>
</div>
</t>
</t>
</td>
</xpath>
<!-- Split the quantity_done by lot -->
<xpath
expr="//table/tbody/tr/td//span[@t-field='raw_line.quantity_done']/parent::div"
position="attributes"
>
<attribute
name="t-if"
t-translation="off"
>raw_line.product_id.tracking != 'lot'</attribute>
</xpath>
<xpath
expr="//table/tbody/tr/td//span[@t-field='raw_line.quantity_done']/parent::div"
position="after"
>
<div t-if="raw_line.product_id.tracking == 'lot'">
<t t-foreach="quantity_by_lot.keys()" t-as="lot">
<div t-if="lot" t-esc="quantity_by_lot[lot]" />
</t>
<div t-if="False in quantity_by_lot" t-esc="quantity_by_lot[False]" />
</div>
</xpath>
</template>

</odoo>
Loading

0 comments on commit 129efeb

Please sign in to comment.