mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[ADD] mrp_package_propagation
This commit is contained in:
94
mrp_package_propagation/README.rst
Normal file
94
mrp_package_propagation/README.rst
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
=======================
|
||||||
|
MRP Package Propagation
|
||||||
|
=======================
|
||||||
|
|
||||||
|
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
!! This file is generated by oca-gen-addon-readme !!
|
||||||
|
!! changes will be overwritten. !!
|
||||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
|
||||||
|
:target: https://odoo-community.org/page/development-status
|
||||||
|
:alt: Alpha
|
||||||
|
.. |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-lightgray.png?logo=github
|
||||||
|
:target: https://github.com/OCA/manufacture/tree/14.0/mrp_package_propagation
|
||||||
|
:alt: OCA/manufacture
|
||||||
|
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||||
|
:target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_package_propagation
|
||||||
|
:alt: Translate me on Weblate
|
||||||
|
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||||
|
:target: https://runbot.odoo-community.org/runbot/129/14.0
|
||||||
|
:alt: Try me on Runbot
|
||||||
|
|
||||||
|
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||||
|
|
||||||
|
Allow to propagate a package from a component to a finished product.
|
||||||
|
|
||||||
|
.. IMPORTANT::
|
||||||
|
This is an alpha version, the data model and design can change at any time without warning.
|
||||||
|
Only for development or testing purpose, do not use in production.
|
||||||
|
`More details on development status <https://odoo-community.org/page/development-status>`_
|
||||||
|
|
||||||
|
**Table of contents**
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
On the BoM:
|
||||||
|
|
||||||
|
* enable the option "Package Propagation"
|
||||||
|
* flag one of the BoM line with "Propagate Package"
|
||||||
|
|
||||||
|
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 <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_package_propagation%0Aversion:%2014.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
|
||||||
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
|
* Sébastien Alix <sebastien.alix@camptocamp.com>
|
||||||
|
|
||||||
|
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-sebalix| image:: https://github.com/sebalix.png?size=40px
|
||||||
|
:target: https://github.com/sebalix
|
||||||
|
:alt: sebalix
|
||||||
|
|
||||||
|
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|
||||||
|
|
||||||
|
|maintainer-sebalix|
|
||||||
|
|
||||||
|
This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/14.0/mrp_package_propagation>`_ project on GitHub.
|
||||||
|
|
||||||
|
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||||
1
mrp_package_propagation/__init__.py
Normal file
1
mrp_package_propagation/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
20
mrp_package_propagation/__manifest__.py
Normal file
20
mrp_package_propagation/__manifest__.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Copyright 2023 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
{
|
||||||
|
"name": "MRP Package Propagation",
|
||||||
|
"version": "14.0.1.0.0",
|
||||||
|
"development_status": "Alpha",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"author": "Camptocamp, Odoo Community Association (OCA)",
|
||||||
|
"maintainers": ["sebalix"],
|
||||||
|
"summary": "Propagate a package from a component to a finished product",
|
||||||
|
"website": "https://github.com/OCA/manufacture",
|
||||||
|
"category": "Manufacturing",
|
||||||
|
"depends": ["mrp"],
|
||||||
|
"data": [
|
||||||
|
"views/mrp_bom.xml",
|
||||||
|
"views/mrp_production.xml",
|
||||||
|
],
|
||||||
|
"installable": True,
|
||||||
|
"application": False,
|
||||||
|
}
|
||||||
4
mrp_package_propagation/models/__init__.py
Normal file
4
mrp_package_propagation/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
from . import mrp_bom
|
||||||
|
from . import mrp_bom_line
|
||||||
|
from . import mrp_production
|
||||||
|
from . import stock_move
|
||||||
61
mrp_package_propagation/models/mrp_bom.py
Normal file
61
mrp_package_propagation/models/mrp_bom.py
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# Copyright 2022 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
|
||||||
|
from odoo import _, api, fields, models
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
|
class MrpBom(models.Model):
|
||||||
|
_inherit = "mrp.bom"
|
||||||
|
|
||||||
|
package_propagation = fields.Boolean(
|
||||||
|
default=False,
|
||||||
|
help=(
|
||||||
|
"Allow to propagate the package "
|
||||||
|
"from a component to the finished product."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
display_package_propagation = fields.Boolean(
|
||||||
|
compute="_compute_display_package_propagation"
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends(
|
||||||
|
"type",
|
||||||
|
"product_tmpl_id.tracking",
|
||||||
|
"product_qty",
|
||||||
|
"product_uom_id",
|
||||||
|
"bom_line_ids.product_id.tracking",
|
||||||
|
"bom_line_ids.product_qty",
|
||||||
|
"bom_line_ids.product_uom_id",
|
||||||
|
)
|
||||||
|
def _compute_display_package_propagation(self):
|
||||||
|
"""Check if a package can be propagated.
|
||||||
|
|
||||||
|
A package can be propagated from a component to the finished product if
|
||||||
|
the type of the BoM is normal (Manufacture this product)
|
||||||
|
"""
|
||||||
|
for bom in self:
|
||||||
|
bom.display_package_propagation = (
|
||||||
|
bom.type in self._get_package_propagation_bom_types()
|
||||||
|
)
|
||||||
|
|
||||||
|
def _get_package_propagation_bom_types(self):
|
||||||
|
return ["normal"]
|
||||||
|
|
||||||
|
@api.onchange("display_package_propagation")
|
||||||
|
def onchange_display_package_propagation(self):
|
||||||
|
if not self.display_package_propagation:
|
||||||
|
self.package_propagation = False
|
||||||
|
|
||||||
|
@api.constrains("package_propagation")
|
||||||
|
def _check_propagate_package(self):
|
||||||
|
for bom in self:
|
||||||
|
if not bom.package_propagation:
|
||||||
|
continue
|
||||||
|
if not bom.bom_line_ids.filtered("propagate_package"):
|
||||||
|
raise ValidationError(
|
||||||
|
_(
|
||||||
|
"With 'Package Propagation' enabled, a line has "
|
||||||
|
"to be configured with the 'Propagate Package' option."
|
||||||
|
)
|
||||||
|
)
|
||||||
64
mrp_package_propagation/models/mrp_bom_line.py
Normal file
64
mrp_package_propagation/models/mrp_bom_line.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
# Copyright 2023 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
|
||||||
|
from odoo import _, api, fields, models, tools
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
|
class MrpBomLine(models.Model):
|
||||||
|
_inherit = "mrp.bom.line"
|
||||||
|
|
||||||
|
propagate_package = fields.Boolean(
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
|
display_propagate_package = fields.Boolean(
|
||||||
|
compute="_compute_display_propagate_package"
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends(
|
||||||
|
"bom_id.display_package_propagation",
|
||||||
|
"bom_id.package_propagation",
|
||||||
|
)
|
||||||
|
def _compute_display_propagate_package(self):
|
||||||
|
for line in self:
|
||||||
|
line.display_propagate_package = (
|
||||||
|
line.bom_id.display_package_propagation
|
||||||
|
and line.bom_id.package_propagation
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.constrains("propagate_package")
|
||||||
|
def _check_propagate_package(self):
|
||||||
|
"""
|
||||||
|
This function should check:
|
||||||
|
|
||||||
|
- if the bom has package_propagation marked, there is one and
|
||||||
|
only one line of this bom with `propagate_package` marked.
|
||||||
|
- if the component qty is 1 unit
|
||||||
|
"""
|
||||||
|
uom_unit = self.env.ref("uom.product_uom_unit")
|
||||||
|
for line in self:
|
||||||
|
if not line.bom_id.package_propagation:
|
||||||
|
continue
|
||||||
|
lines_to_propagate = line.bom_id.bom_line_ids.filtered(
|
||||||
|
lambda o: o.propagate_package
|
||||||
|
)
|
||||||
|
if len(lines_to_propagate) > 1:
|
||||||
|
raise ValidationError(
|
||||||
|
_(
|
||||||
|
"Only one component can propagate its package "
|
||||||
|
"to the finished product."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
qty_ok = (
|
||||||
|
tools.float_compare(
|
||||||
|
line.product_qty, 1, precision_rounding=uom_unit.rounding
|
||||||
|
)
|
||||||
|
== 0
|
||||||
|
)
|
||||||
|
if line.propagate_package and (
|
||||||
|
line.product_uom_id != uom_unit or not qty_ok
|
||||||
|
):
|
||||||
|
raise ValidationError(
|
||||||
|
_("The component propagating the package must consume 1 %s.")
|
||||||
|
% uom_unit.display_name
|
||||||
|
)
|
||||||
105
mrp_package_propagation/models/mrp_production.py
Normal file
105
mrp_package_propagation/models/mrp_production.py
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
# Copyright 2023 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
|
||||||
|
from odoo import _, api, fields, models, tools
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
|
class MrpProduction(models.Model):
|
||||||
|
_inherit = "mrp.production"
|
||||||
|
|
||||||
|
is_package_propagated = fields.Boolean(
|
||||||
|
default=False,
|
||||||
|
readonly=True,
|
||||||
|
string="Is package propagated?",
|
||||||
|
help="Package is propagated from a component to the finished product.",
|
||||||
|
)
|
||||||
|
propagated_package_id = fields.Many2one(
|
||||||
|
comodel_name="stock.quant.package",
|
||||||
|
compute="_compute_propagated_package_id",
|
||||||
|
string="Propagated package",
|
||||||
|
help=(
|
||||||
|
"The BoM used on this manufacturing order is set to propagate "
|
||||||
|
"package from one of its components. The value will be "
|
||||||
|
"computed once the corresponding component is selected."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends(
|
||||||
|
"move_raw_ids.propagate_package",
|
||||||
|
"move_raw_ids.move_line_ids.qty_done",
|
||||||
|
)
|
||||||
|
def _compute_propagated_package_id(self):
|
||||||
|
for order in self:
|
||||||
|
order.propagated_package_id = False
|
||||||
|
move_with_package = order.move_raw_ids.filtered(
|
||||||
|
lambda o: o.propagate_package
|
||||||
|
)
|
||||||
|
line_with_package = move_with_package.move_line_ids.filtered(
|
||||||
|
lambda l: l.package_id
|
||||||
|
)
|
||||||
|
if len(line_with_package) == 1:
|
||||||
|
order.propagated_package_id = line_with_package.package_id
|
||||||
|
|
||||||
|
@api.onchange("bom_id")
|
||||||
|
def _onchange_bom_id_package_propagation(self):
|
||||||
|
self.is_package_propagated = self.bom_id.package_propagation
|
||||||
|
|
||||||
|
def action_confirm(self):
|
||||||
|
res = super().action_confirm()
|
||||||
|
self._check_package_propagation()
|
||||||
|
self._set_package_propagation_data_from_bom()
|
||||||
|
return res
|
||||||
|
|
||||||
|
def _check_package_propagation(self):
|
||||||
|
"""Ensure we can propagate the component package from the BoM."""
|
||||||
|
for order in self:
|
||||||
|
bom = order.bom_id
|
||||||
|
if not bom.package_propagation:
|
||||||
|
continue
|
||||||
|
qty_ok = (
|
||||||
|
tools.float_compare(
|
||||||
|
order.product_qty,
|
||||||
|
bom.product_qty,
|
||||||
|
precision_rounding=bom.product_uom_id.rounding,
|
||||||
|
)
|
||||||
|
== 0
|
||||||
|
)
|
||||||
|
if not qty_ok or order.product_uom_id != bom.product_uom_id:
|
||||||
|
raise UserError(
|
||||||
|
_(
|
||||||
|
"The BoM is propagating a package from one component.\n"
|
||||||
|
"As such, the manufacturing order is forced to produce "
|
||||||
|
"the same quantity than the BoM: %s %s"
|
||||||
|
)
|
||||||
|
% (bom.product_qty, bom.product_uom_id.display_name)
|
||||||
|
)
|
||||||
|
|
||||||
|
def _set_package_propagation_data_from_bom(self):
|
||||||
|
"""Copy information from BoM to the manufacturing order."""
|
||||||
|
for order in self:
|
||||||
|
order.is_package_propagated = order.bom_id.package_propagation
|
||||||
|
for move in order.move_raw_ids:
|
||||||
|
move.propagate_package = move.bom_line_id.propagate_package
|
||||||
|
|
||||||
|
def _cal_price(self, consumed_moves):
|
||||||
|
# Overridden to propagate the package of the component
|
||||||
|
# to the finished product
|
||||||
|
# NOTE: this is the only method called in '_post_inventory' between
|
||||||
|
# the creation of the stock.move.line record on the finished move,
|
||||||
|
# and its validation.
|
||||||
|
self._create_and_assign_propagated_package()
|
||||||
|
return super()._cal_price(consumed_moves)
|
||||||
|
|
||||||
|
def _create_and_assign_propagated_package(self):
|
||||||
|
for order in self:
|
||||||
|
if not order.is_package_propagated:
|
||||||
|
continue
|
||||||
|
finish_moves = order.move_finished_ids.filtered(
|
||||||
|
lambda m: m.product_id == order.product_id
|
||||||
|
and m.state not in ("done", "cancel")
|
||||||
|
)
|
||||||
|
if finish_moves.move_line_ids:
|
||||||
|
finish_moves.move_line_ids.result_package_id = (
|
||||||
|
order.propagated_package_id
|
||||||
|
)
|
||||||
13
mrp_package_propagation/models/stock_move.py
Normal file
13
mrp_package_propagation/models/stock_move.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Copyright 2023 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class StockMove(models.Model):
|
||||||
|
_inherit = "stock.move"
|
||||||
|
|
||||||
|
propagate_package = fields.Boolean(
|
||||||
|
default=False,
|
||||||
|
readonly=True,
|
||||||
|
)
|
||||||
1
mrp_package_propagation/readme/CONTRIBUTORS.rst
Normal file
1
mrp_package_propagation/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* Sébastien Alix <sebastien.alix@camptocamp.com>
|
||||||
11
mrp_package_propagation/readme/DESCRIPTION.rst
Normal file
11
mrp_package_propagation/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
Allow to propagate a package from a component to a finished product.
|
||||||
|
|
||||||
|
This is useful for instance if you want to keep the box of one of the component
|
||||||
|
(which could have already a label stuck on it) for your finished product.
|
||||||
|
|
||||||
|
Two constraints:
|
||||||
|
|
||||||
|
* the component quantity has to be 1 unit
|
||||||
|
* the manufacturing order has to produce exactly the BoM quantity
|
||||||
|
|
||||||
|
This is to ensure we get only one package reserved for the given component.
|
||||||
4
mrp_package_propagation/readme/USAGE.rst
Normal file
4
mrp_package_propagation/readme/USAGE.rst
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
On the BoM:
|
||||||
|
|
||||||
|
* enable the option "Package Propagation"
|
||||||
|
* flag one of the BoM line with "Propagate Package"
|
||||||
436
mrp_package_propagation/static/description/index.html
Normal file
436
mrp_package_propagation/static/description/index.html
Normal file
@@ -0,0 +1,436 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
|
||||||
|
<title>MRP Package Propagation</title>
|
||||||
|
<style type="text/css">
|
||||||
|
|
||||||
|
/*
|
||||||
|
:Author: David Goodger (goodger@python.org)
|
||||||
|
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
|
||||||
|
:Copyright: This stylesheet has been placed in the public domain.
|
||||||
|
|
||||||
|
Default cascading style sheet for the HTML output of Docutils.
|
||||||
|
|
||||||
|
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
|
||||||
|
customize this style sheet.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* used to remove borders from tables and images */
|
||||||
|
.borderless, table.borderless td, table.borderless th {
|
||||||
|
border: 0 }
|
||||||
|
|
||||||
|
table.borderless td, table.borderless th {
|
||||||
|
/* Override padding for "table.docutils td" with "! important".
|
||||||
|
The right padding separates the table cells. */
|
||||||
|
padding: 0 0.5em 0 0 ! important }
|
||||||
|
|
||||||
|
.first {
|
||||||
|
/* Override more specific margin styles with "! important". */
|
||||||
|
margin-top: 0 ! important }
|
||||||
|
|
||||||
|
.last, .with-subtitle {
|
||||||
|
margin-bottom: 0 ! important }
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display: none }
|
||||||
|
|
||||||
|
.subscript {
|
||||||
|
vertical-align: sub;
|
||||||
|
font-size: smaller }
|
||||||
|
|
||||||
|
.superscript {
|
||||||
|
vertical-align: super;
|
||||||
|
font-size: smaller }
|
||||||
|
|
||||||
|
a.toc-backref {
|
||||||
|
text-decoration: none ;
|
||||||
|
color: black }
|
||||||
|
|
||||||
|
blockquote.epigraph {
|
||||||
|
margin: 2em 5em ; }
|
||||||
|
|
||||||
|
dl.docutils dd {
|
||||||
|
margin-bottom: 0.5em }
|
||||||
|
|
||||||
|
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Uncomment (and remove this text!) to get bold-faced definition list terms
|
||||||
|
dl.docutils dt {
|
||||||
|
font-weight: bold }
|
||||||
|
*/
|
||||||
|
|
||||||
|
div.abstract {
|
||||||
|
margin: 2em 5em }
|
||||||
|
|
||||||
|
div.abstract p.topic-title {
|
||||||
|
font-weight: bold ;
|
||||||
|
text-align: center }
|
||||||
|
|
||||||
|
div.admonition, div.attention, div.caution, div.danger, div.error,
|
||||||
|
div.hint, div.important, div.note, div.tip, div.warning {
|
||||||
|
margin: 2em ;
|
||||||
|
border: medium outset ;
|
||||||
|
padding: 1em }
|
||||||
|
|
||||||
|
div.admonition p.admonition-title, div.hint p.admonition-title,
|
||||||
|
div.important p.admonition-title, div.note p.admonition-title,
|
||||||
|
div.tip p.admonition-title {
|
||||||
|
font-weight: bold ;
|
||||||
|
font-family: sans-serif }
|
||||||
|
|
||||||
|
div.attention p.admonition-title, div.caution p.admonition-title,
|
||||||
|
div.danger p.admonition-title, div.error p.admonition-title,
|
||||||
|
div.warning p.admonition-title, .code .error {
|
||||||
|
color: red ;
|
||||||
|
font-weight: bold ;
|
||||||
|
font-family: sans-serif }
|
||||||
|
|
||||||
|
/* Uncomment (and remove this text!) to get reduced vertical space in
|
||||||
|
compound paragraphs.
|
||||||
|
div.compound .compound-first, div.compound .compound-middle {
|
||||||
|
margin-bottom: 0.5em }
|
||||||
|
|
||||||
|
div.compound .compound-last, div.compound .compound-middle {
|
||||||
|
margin-top: 0.5em }
|
||||||
|
*/
|
||||||
|
|
||||||
|
div.dedication {
|
||||||
|
margin: 2em 5em ;
|
||||||
|
text-align: center ;
|
||||||
|
font-style: italic }
|
||||||
|
|
||||||
|
div.dedication p.topic-title {
|
||||||
|
font-weight: bold ;
|
||||||
|
font-style: normal }
|
||||||
|
|
||||||
|
div.figure {
|
||||||
|
margin-left: 2em ;
|
||||||
|
margin-right: 2em }
|
||||||
|
|
||||||
|
div.footer, div.header {
|
||||||
|
clear: both;
|
||||||
|
font-size: smaller }
|
||||||
|
|
||||||
|
div.line-block {
|
||||||
|
display: block ;
|
||||||
|
margin-top: 1em ;
|
||||||
|
margin-bottom: 1em }
|
||||||
|
|
||||||
|
div.line-block div.line-block {
|
||||||
|
margin-top: 0 ;
|
||||||
|
margin-bottom: 0 ;
|
||||||
|
margin-left: 1.5em }
|
||||||
|
|
||||||
|
div.sidebar {
|
||||||
|
margin: 0 0 0.5em 1em ;
|
||||||
|
border: medium outset ;
|
||||||
|
padding: 1em ;
|
||||||
|
background-color: #ffffee ;
|
||||||
|
width: 40% ;
|
||||||
|
float: right ;
|
||||||
|
clear: right }
|
||||||
|
|
||||||
|
div.sidebar p.rubric {
|
||||||
|
font-family: sans-serif ;
|
||||||
|
font-size: medium }
|
||||||
|
|
||||||
|
div.system-messages {
|
||||||
|
margin: 5em }
|
||||||
|
|
||||||
|
div.system-messages h1 {
|
||||||
|
color: red }
|
||||||
|
|
||||||
|
div.system-message {
|
||||||
|
border: medium outset ;
|
||||||
|
padding: 1em }
|
||||||
|
|
||||||
|
div.system-message p.system-message-title {
|
||||||
|
color: red ;
|
||||||
|
font-weight: bold }
|
||||||
|
|
||||||
|
div.topic {
|
||||||
|
margin: 2em }
|
||||||
|
|
||||||
|
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
||||||
|
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
||||||
|
margin-top: 0.4em }
|
||||||
|
|
||||||
|
h1.title {
|
||||||
|
text-align: center }
|
||||||
|
|
||||||
|
h2.subtitle {
|
||||||
|
text-align: center }
|
||||||
|
|
||||||
|
hr.docutils {
|
||||||
|
width: 75% }
|
||||||
|
|
||||||
|
img.align-left, .figure.align-left, object.align-left, table.align-left {
|
||||||
|
clear: left ;
|
||||||
|
float: left ;
|
||||||
|
margin-right: 1em }
|
||||||
|
|
||||||
|
img.align-right, .figure.align-right, object.align-right, table.align-right {
|
||||||
|
clear: right ;
|
||||||
|
float: right ;
|
||||||
|
margin-left: 1em }
|
||||||
|
|
||||||
|
img.align-center, .figure.align-center, object.align-center {
|
||||||
|
display: block;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.align-center {
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.align-left {
|
||||||
|
text-align: left }
|
||||||
|
|
||||||
|
.align-center {
|
||||||
|
clear: both ;
|
||||||
|
text-align: center }
|
||||||
|
|
||||||
|
.align-right {
|
||||||
|
text-align: right }
|
||||||
|
|
||||||
|
/* reset inner alignment in figures */
|
||||||
|
div.align-right {
|
||||||
|
text-align: inherit }
|
||||||
|
|
||||||
|
/* div.align-center * { */
|
||||||
|
/* text-align: left } */
|
||||||
|
|
||||||
|
.align-top {
|
||||||
|
vertical-align: top }
|
||||||
|
|
||||||
|
.align-middle {
|
||||||
|
vertical-align: middle }
|
||||||
|
|
||||||
|
.align-bottom {
|
||||||
|
vertical-align: bottom }
|
||||||
|
|
||||||
|
ol.simple, ul.simple {
|
||||||
|
margin-bottom: 1em }
|
||||||
|
|
||||||
|
ol.arabic {
|
||||||
|
list-style: decimal }
|
||||||
|
|
||||||
|
ol.loweralpha {
|
||||||
|
list-style: lower-alpha }
|
||||||
|
|
||||||
|
ol.upperalpha {
|
||||||
|
list-style: upper-alpha }
|
||||||
|
|
||||||
|
ol.lowerroman {
|
||||||
|
list-style: lower-roman }
|
||||||
|
|
||||||
|
ol.upperroman {
|
||||||
|
list-style: upper-roman }
|
||||||
|
|
||||||
|
p.attribution {
|
||||||
|
text-align: right ;
|
||||||
|
margin-left: 50% }
|
||||||
|
|
||||||
|
p.caption {
|
||||||
|
font-style: italic }
|
||||||
|
|
||||||
|
p.credits {
|
||||||
|
font-style: italic ;
|
||||||
|
font-size: smaller }
|
||||||
|
|
||||||
|
p.label {
|
||||||
|
white-space: nowrap }
|
||||||
|
|
||||||
|
p.rubric {
|
||||||
|
font-weight: bold ;
|
||||||
|
font-size: larger ;
|
||||||
|
color: maroon ;
|
||||||
|
text-align: center }
|
||||||
|
|
||||||
|
p.sidebar-title {
|
||||||
|
font-family: sans-serif ;
|
||||||
|
font-weight: bold ;
|
||||||
|
font-size: larger }
|
||||||
|
|
||||||
|
p.sidebar-subtitle {
|
||||||
|
font-family: sans-serif ;
|
||||||
|
font-weight: bold }
|
||||||
|
|
||||||
|
p.topic-title {
|
||||||
|
font-weight: bold }
|
||||||
|
|
||||||
|
pre.address {
|
||||||
|
margin-bottom: 0 ;
|
||||||
|
margin-top: 0 ;
|
||||||
|
font: inherit }
|
||||||
|
|
||||||
|
pre.literal-block, pre.doctest-block, pre.math, pre.code {
|
||||||
|
margin-left: 2em ;
|
||||||
|
margin-right: 2em }
|
||||||
|
|
||||||
|
pre.code .ln { color: grey; } /* line numbers */
|
||||||
|
pre.code, code { background-color: #eeeeee }
|
||||||
|
pre.code .comment, code .comment { color: #5C6576 }
|
||||||
|
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
|
||||||
|
pre.code .literal.string, code .literal.string { color: #0C5404 }
|
||||||
|
pre.code .name.builtin, code .name.builtin { color: #352B84 }
|
||||||
|
pre.code .deleted, code .deleted { background-color: #DEB0A1}
|
||||||
|
pre.code .inserted, code .inserted { background-color: #A3D289}
|
||||||
|
|
||||||
|
span.classifier {
|
||||||
|
font-family: sans-serif ;
|
||||||
|
font-style: oblique }
|
||||||
|
|
||||||
|
span.classifier-delimiter {
|
||||||
|
font-family: sans-serif ;
|
||||||
|
font-weight: bold }
|
||||||
|
|
||||||
|
span.interpreted {
|
||||||
|
font-family: sans-serif }
|
||||||
|
|
||||||
|
span.option {
|
||||||
|
white-space: nowrap }
|
||||||
|
|
||||||
|
span.pre {
|
||||||
|
white-space: pre }
|
||||||
|
|
||||||
|
span.problematic {
|
||||||
|
color: red }
|
||||||
|
|
||||||
|
span.section-subtitle {
|
||||||
|
/* font-size relative to parent (h1..h6 element) */
|
||||||
|
font-size: 80% }
|
||||||
|
|
||||||
|
table.citation {
|
||||||
|
border-left: solid 1px gray;
|
||||||
|
margin-left: 1px }
|
||||||
|
|
||||||
|
table.docinfo {
|
||||||
|
margin: 2em 4em }
|
||||||
|
|
||||||
|
table.docutils {
|
||||||
|
margin-top: 0.5em ;
|
||||||
|
margin-bottom: 0.5em }
|
||||||
|
|
||||||
|
table.footnote {
|
||||||
|
border-left: solid 1px black;
|
||||||
|
margin-left: 1px }
|
||||||
|
|
||||||
|
table.docutils td, table.docutils th,
|
||||||
|
table.docinfo td, table.docinfo th {
|
||||||
|
padding-left: 0.5em ;
|
||||||
|
padding-right: 0.5em ;
|
||||||
|
vertical-align: top }
|
||||||
|
|
||||||
|
table.docutils th.field-name, table.docinfo th.docinfo-name {
|
||||||
|
font-weight: bold ;
|
||||||
|
text-align: left ;
|
||||||
|
white-space: nowrap ;
|
||||||
|
padding-left: 0 }
|
||||||
|
|
||||||
|
/* "booktabs" style (no vertical lines) */
|
||||||
|
table.docutils.booktabs {
|
||||||
|
border: 0px;
|
||||||
|
border-top: 2px solid;
|
||||||
|
border-bottom: 2px solid;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
table.docutils.booktabs * {
|
||||||
|
border: 0px;
|
||||||
|
}
|
||||||
|
table.docutils.booktabs th {
|
||||||
|
border-bottom: thin solid;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
||||||
|
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
||||||
|
font-size: 100% }
|
||||||
|
|
||||||
|
ul.auto-toc {
|
||||||
|
list-style-type: none }
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="document" id="mrp-package-propagation">
|
||||||
|
<h1 class="title">MRP Package Propagation</h1>
|
||||||
|
|
||||||
|
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
!! This file is generated by oca-gen-addon-readme !!
|
||||||
|
!! changes will be overwritten. !!
|
||||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||||
|
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/manufacture/tree/14.0/mrp_package_propagation"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_package_propagation"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/129/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||||
|
<p>Allow to propagate a package from a component to a finished product.</p>
|
||||||
|
<div class="admonition important">
|
||||||
|
<p class="first admonition-title">Important</p>
|
||||||
|
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
|
||||||
|
Only for development or testing purpose, do not use in production.
|
||||||
|
<a class="reference external" href="https://odoo-community.org/page/development-status">More details on development status</a></p>
|
||||||
|
</div>
|
||||||
|
<p><strong>Table of contents</strong></p>
|
||||||
|
<div class="contents local topic" id="contents">
|
||||||
|
<ul class="simple">
|
||||||
|
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
|
||||||
|
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
|
||||||
|
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
|
||||||
|
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
|
||||||
|
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
|
||||||
|
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="usage">
|
||||||
|
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
|
||||||
|
<p>On the BoM:</p>
|
||||||
|
<ul class="simple">
|
||||||
|
<li>enable the option “Package Propagation”</li>
|
||||||
|
<li>flag one of the BoM line with “Propagate Package”</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="bug-tracker">
|
||||||
|
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
|
||||||
|
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/manufacture/issues">GitHub Issues</a>.
|
||||||
|
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
|
||||||
|
<a class="reference external" href="https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_package_propagation%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||||
|
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="credits">
|
||||||
|
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
|
||||||
|
<div class="section" id="authors">
|
||||||
|
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
|
||||||
|
<ul class="simple">
|
||||||
|
<li>Camptocamp</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="contributors">
|
||||||
|
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
|
||||||
|
<ul class="simple">
|
||||||
|
<li>Sébastien Alix <<a class="reference external" href="mailto:sebastien.alix@camptocamp.com">sebastien.alix@camptocamp.com</a>></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="maintainers">
|
||||||
|
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
|
||||||
|
<p>This module is maintained by the OCA.</p>
|
||||||
|
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||||
|
<p>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.</p>
|
||||||
|
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
|
||||||
|
<p><a class="reference external" href="https://github.com/sebalix"><img alt="sebalix" src="https://github.com/sebalix.png?size=40px" /></a></p>
|
||||||
|
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/14.0/mrp_package_propagation">OCA/manufacture</a> project on GitHub.</p>
|
||||||
|
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
2
mrp_package_propagation/tests/__init__.py
Normal file
2
mrp_package_propagation/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from . import test_mrp_bom
|
||||||
|
from . import test_mrp_production
|
||||||
69
mrp_package_propagation/tests/common.py
Normal file
69
mrp_package_propagation/tests/common.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# Copyright 2023 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
|
from odoo.tests import common
|
||||||
|
|
||||||
|
|
||||||
|
class Common(common.SavepointCase):
|
||||||
|
|
||||||
|
PACKAGE_NAME = "PROPAGATED-PKG"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
||||||
|
cls.bom = cls.env.ref("mrp.mrp_bom_desk")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _update_qty_in_location(
|
||||||
|
cls, location, product, quantity, package=None, lot=None, in_date=None
|
||||||
|
):
|
||||||
|
quants = cls.env["stock.quant"]._gather(
|
||||||
|
product, location, lot_id=lot, package_id=package, strict=True
|
||||||
|
)
|
||||||
|
# this method adds the quantity to the current quantity, so remove it
|
||||||
|
quantity -= sum(quants.mapped("quantity"))
|
||||||
|
cls.env["stock.quant"]._update_available_quantity(
|
||||||
|
product,
|
||||||
|
location,
|
||||||
|
quantity,
|
||||||
|
package_id=package,
|
||||||
|
lot_id=lot,
|
||||||
|
in_date=in_date,
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _update_stock_component_qty(cls, order=None, bom=None, location=None):
|
||||||
|
if not order and not bom:
|
||||||
|
return
|
||||||
|
if order:
|
||||||
|
bom = order.bom_id
|
||||||
|
if not location:
|
||||||
|
location = cls.env.ref("stock.stock_location_stock")
|
||||||
|
for line in bom.bom_line_ids:
|
||||||
|
if line.product_id.type != "product":
|
||||||
|
continue
|
||||||
|
lot = package = None
|
||||||
|
if line.product_id.tracking != "none":
|
||||||
|
lot_name = "".join(
|
||||||
|
random.choice(string.ascii_lowercase) for i in range(10)
|
||||||
|
)
|
||||||
|
vals = {
|
||||||
|
"product_id": line.product_id.id,
|
||||||
|
"company_id": line.company_id.id,
|
||||||
|
"name": lot_name,
|
||||||
|
}
|
||||||
|
lot = cls.env["stock.production.lot"].create(vals)
|
||||||
|
if line.propagate_package:
|
||||||
|
vals = {"name": cls.PACKAGE_NAME}
|
||||||
|
package = cls.env["stock.quant.package"].create(vals)
|
||||||
|
cls._update_qty_in_location(
|
||||||
|
location,
|
||||||
|
line.product_id,
|
||||||
|
line.product_qty,
|
||||||
|
package=package,
|
||||||
|
lot=lot,
|
||||||
|
)
|
||||||
50
mrp_package_propagation/tests/test_mrp_bom.py
Normal file
50
mrp_package_propagation/tests/test_mrp_bom.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# Copyright 2023 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
from odoo.tests.common import Form
|
||||||
|
|
||||||
|
from .common import Common
|
||||||
|
|
||||||
|
|
||||||
|
class TestMrpBom(Common):
|
||||||
|
def test_bom_display_package_propagation(self):
|
||||||
|
self.assertTrue(self.bom.display_package_propagation)
|
||||||
|
|
||||||
|
def test_bom_line_check_propagate_package_multi(self):
|
||||||
|
form = Form(self.bom)
|
||||||
|
form.package_propagation = True
|
||||||
|
# Flag more than one line to propagate
|
||||||
|
for i in range(len(form.bom_line_ids)):
|
||||||
|
line_form = form.bom_line_ids.edit(i)
|
||||||
|
line_form.propagate_package = True
|
||||||
|
line_form.save()
|
||||||
|
with self.assertRaisesRegex(ValidationError, "Only one component"):
|
||||||
|
form.save()
|
||||||
|
|
||||||
|
def test_bom_line_wrong_unit(self):
|
||||||
|
form = Form(self.bom)
|
||||||
|
form.package_propagation = True
|
||||||
|
# Set the wrong UoM on the line
|
||||||
|
line_form = form.bom_line_ids.edit(1)
|
||||||
|
line_form.propagate_package = True
|
||||||
|
line_form.product_uom_id = self.env.ref("uom.product_uom_dozen")
|
||||||
|
line_form.save()
|
||||||
|
with self.assertRaisesRegex(ValidationError, "The component propagating"):
|
||||||
|
form.save()
|
||||||
|
|
||||||
|
def test_bom_line_wrong_qty(self):
|
||||||
|
form = Form(self.bom)
|
||||||
|
form.package_propagation = True
|
||||||
|
# Set the wrong qty on the line
|
||||||
|
line_form = form.bom_line_ids.edit(1)
|
||||||
|
line_form.propagate_package = True
|
||||||
|
line_form.product_qty = 2
|
||||||
|
line_form.save()
|
||||||
|
with self.assertRaisesRegex(ValidationError, "The component propagating"):
|
||||||
|
form.save()
|
||||||
|
|
||||||
|
def test_bom_check_propagate_package(self):
|
||||||
|
# Configure the BoM to propagate the package without enabling any line
|
||||||
|
with self.assertRaisesRegex(ValidationError, "a line has to be configured"):
|
||||||
|
self.bom.package_propagation = True
|
||||||
63
mrp_package_propagation/tests/test_mrp_production.py
Normal file
63
mrp_package_propagation/tests/test_mrp_production.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
# Copyright 2023 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
from odoo.tests.common import Form
|
||||||
|
|
||||||
|
from .common import Common
|
||||||
|
|
||||||
|
|
||||||
|
class TestMrpProduction(Common):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
# Configure the BoM to propagate package
|
||||||
|
with Form(cls.bom) as form:
|
||||||
|
form.package_propagation = True
|
||||||
|
line_form = form.bom_line_ids.edit(0) # Line tracked by SN
|
||||||
|
line_form.propagate_package = True
|
||||||
|
line_form.save()
|
||||||
|
form.save()
|
||||||
|
with Form(cls.env["mrp.production"]) as form:
|
||||||
|
form.bom_id = cls.bom
|
||||||
|
cls.order = form.save()
|
||||||
|
|
||||||
|
def _set_qty_done(self, order):
|
||||||
|
for line in order.move_raw_ids.move_line_ids:
|
||||||
|
line.qty_done = line.product_uom_qty
|
||||||
|
order.qty_producing = order.product_qty
|
||||||
|
|
||||||
|
def test_order_check_package_propagation(self):
|
||||||
|
self.assertTrue(self.order.is_package_propagated)
|
||||||
|
# Set a wrong quantity to produce
|
||||||
|
self.order.product_qty = 2
|
||||||
|
with self.assertRaisesRegex(UserError, "The BoM is propagating a package"):
|
||||||
|
self.order.action_confirm()
|
||||||
|
self.order.product_qty = self.order.bom_id.product_qty
|
||||||
|
# Set a wrong UoM
|
||||||
|
self.order.product_uom_id = self.env.ref("uom.product_uom_dozen")
|
||||||
|
with self.assertRaisesRegex(UserError, "The BoM is propagating a package"):
|
||||||
|
self.order.action_confirm()
|
||||||
|
# Restore expected values to get the order validated
|
||||||
|
self.order.product_uom_id = self.order.bom_id.product_uom_id
|
||||||
|
self.order.product_qty = self.order.bom_id.product_qty
|
||||||
|
self.order.action_confirm()
|
||||||
|
|
||||||
|
def test_order_propagated_package_id(self):
|
||||||
|
self.assertTrue(self.order.is_package_propagated) # set by onchange
|
||||||
|
self._update_stock_component_qty(self.order)
|
||||||
|
self.order.action_confirm()
|
||||||
|
self.order.action_assign()
|
||||||
|
self.assertTrue(self.order.is_package_propagated) # set by action_confirm
|
||||||
|
self.assertTrue(any(self.order.move_raw_ids.mapped("propagate_package")))
|
||||||
|
self._set_qty_done(self.order)
|
||||||
|
self.assertEqual(self.order.propagated_package_id.name, self.PACKAGE_NAME)
|
||||||
|
|
||||||
|
def test_order_post_inventory(self):
|
||||||
|
self._update_stock_component_qty(self.order)
|
||||||
|
self.order.action_confirm()
|
||||||
|
self.order.action_assign()
|
||||||
|
self._set_qty_done(self.order)
|
||||||
|
self.order.action_generate_serial()
|
||||||
|
self.order.button_mark_done()
|
||||||
|
self.assertEqual(self.order.propagated_package_id.name, self.PACKAGE_NAME)
|
||||||
28
mrp_package_propagation/views/mrp_bom.xml
Normal file
28
mrp_package_propagation/views/mrp_bom.xml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<!-- Copyright 2023 Camptocamp SA
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="mrp_bom_form_view" model="ir.ui.view">
|
||||||
|
<field name="name">mrp.bom.form.inherit</field>
|
||||||
|
<field name="model">mrp.bom</field>
|
||||||
|
<field name="inherit_id" ref="mrp.mrp_bom_form_view" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="company_id" position="after">
|
||||||
|
<field name="display_package_propagation" invisible="1" />
|
||||||
|
<field
|
||||||
|
name="package_propagation"
|
||||||
|
attrs="{'invisible': [('display_package_propagation', '=', False)]}"
|
||||||
|
/>
|
||||||
|
</field>
|
||||||
|
<xpath expr="//field[@name='bom_line_ids']/tree" position="inside">
|
||||||
|
<field name="display_propagate_package" invisible="1" />
|
||||||
|
<field
|
||||||
|
name="propagate_package"
|
||||||
|
attrs="{'column_invisible': ['|', ('parent.display_package_propagation', '=', False), ('parent.package_propagation', '=', False)]}"
|
||||||
|
/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
28
mrp_package_propagation/views/mrp_production.xml
Normal file
28
mrp_package_propagation/views/mrp_production.xml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<!-- Copyright 2023 Camptocamp SA
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="mrp_production_form_view" model="ir.ui.view">
|
||||||
|
<field name="name">mrp.production.form.inherit</field>
|
||||||
|
<field name="model">mrp.production</field>
|
||||||
|
<field name="inherit_id" ref="mrp.mrp_production_form_view" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<!-- Place new fields in the first group while being compatible with OE -->
|
||||||
|
<xpath expr="//field[@name='id']/.." position="inside">
|
||||||
|
<field
|
||||||
|
name="is_package_propagated"
|
||||||
|
force_save="1"
|
||||||
|
attrs="{'invisible': [('is_package_propagated', '=', False)]}"
|
||||||
|
/>
|
||||||
|
</xpath>
|
||||||
|
<label for="lot_producing_id" position="before">
|
||||||
|
<field
|
||||||
|
name="propagated_package_id"
|
||||||
|
attrs="{'invisible': [('is_package_propagated', '=', False)]}"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../mrp_package_propagation
|
||||||
6
setup/mrp_package_propagation/setup.py
Normal file
6
setup/mrp_package_propagation/setup.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user