mirror of
https://github.com/bringout/oca-mrp.git
synced 2026-04-21 00:52:04 +02:00
Initial commit: OCA Mrp packages (117 packages)
This commit is contained in:
commit
277e84fd7a
4403 changed files with 395154 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
from . import mrp_bom_line
|
||||
from . import mrp_production
|
||||
from . import stock_move
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
# Copyright 2023 Moduon Team S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class MrpBomLine(models.Model):
|
||||
_inherit = "mrp.bom.line"
|
||||
|
||||
product_packaging_id = fields.Many2one(
|
||||
comodel_name="product.packaging",
|
||||
string="Packaging",
|
||||
compute="_compute_product_packaging",
|
||||
store=True,
|
||||
readonly=False,
|
||||
domain="[('product_id', '=', product_id)]",
|
||||
check_company=True,
|
||||
)
|
||||
product_packaging_qty = fields.Float(
|
||||
string="Packaging Qty.",
|
||||
compute="_compute_product_packaging",
|
||||
digits="Product Unit of Measure",
|
||||
store=True,
|
||||
readonly=False,
|
||||
)
|
||||
|
||||
@api.depends("product_id", "product_qty", "product_uom_id")
|
||||
def _compute_product_packaging(self):
|
||||
"""Set the appropriate packaging for the product qty."""
|
||||
for one in self:
|
||||
one.product_packaging_id = (
|
||||
one.product_id.packaging_ids._find_suitable_product_packaging(
|
||||
one.product_qty, one.product_uom_id
|
||||
)
|
||||
)
|
||||
if not one.product_packaging_id:
|
||||
one.product_packaging_qty = 0
|
||||
continue
|
||||
uom_qty_per_package = (
|
||||
one.product_packaging_id.product_uom_id._compute_quantity(
|
||||
one.product_packaging_id.qty, one.product_uom_id
|
||||
)
|
||||
)
|
||||
one.product_packaging_qty = (
|
||||
one.product_packaging_id._check_qty(one.product_qty, one.product_uom_id)
|
||||
/ uom_qty_per_package
|
||||
)
|
||||
|
||||
@api.onchange("product_packaging_id", "product_packaging_qty")
|
||||
def _onchange_product_packaging_set_qty(self):
|
||||
"""When interactively setting a new packaging, set default qty values."""
|
||||
if not self.product_packaging_id:
|
||||
return
|
||||
self.product_qty = (
|
||||
self.product_packaging_qty
|
||||
* self.product_uom_id._compute_quantity(
|
||||
self.product_packaging_id.qty,
|
||||
self.product_packaging_id.product_uom_id,
|
||||
)
|
||||
)
|
||||
|
||||
@api.onchange("product_id")
|
||||
def _onchange_product_set_qty_from_packaging(self):
|
||||
"""When interactively setting a new product, set default packaging values."""
|
||||
default_packaging = self.product_id.packaging_ids[:1]
|
||||
if default_packaging:
|
||||
self.product_uom_id = default_packaging.product_uom_id
|
||||
self.product_qty = default_packaging.qty
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
# Copyright 2024 Moduon Team S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)
|
||||
from odoo import models
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = "mrp.production"
|
||||
|
||||
def _get_move_raw_values(
|
||||
self,
|
||||
product_id,
|
||||
product_uom_qty,
|
||||
product_uom,
|
||||
operation_id=False,
|
||||
bom_line=False,
|
||||
):
|
||||
"""Include packaging in new move values."""
|
||||
result = super()._get_move_raw_values(
|
||||
product_id,
|
||||
product_uom_qty,
|
||||
product_uom,
|
||||
operation_id=operation_id,
|
||||
bom_line=bom_line,
|
||||
)
|
||||
if bom_line and bom_line.product_packaging_id:
|
||||
result["product_packaging_id"] = bom_line.product_packaging_id.id
|
||||
return result
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
# Copyright 2023 Moduon Team S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)
|
||||
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = "stock.move"
|
||||
|
||||
@api.model
|
||||
def _packaging_vals_from_bom_line(self, vals):
|
||||
"""Fill vals with packaging info from BoM line."""
|
||||
try:
|
||||
bom_line = self.env["mrp.bom.line"].browse(vals["bom_line_id"])
|
||||
except KeyError:
|
||||
# No BoM line, nothing to do
|
||||
return
|
||||
# If bom_line_id is False in vals
|
||||
if not bom_line:
|
||||
return
|
||||
vals.update(
|
||||
{
|
||||
"product_packaging_id": bom_line.product_packaging_id.id,
|
||||
}
|
||||
)
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
"""Inherit packaging from BoM line."""
|
||||
for vals in vals_list:
|
||||
self._packaging_vals_from_bom_line(vals)
|
||||
return super().create(vals_list)
|
||||
|
||||
def write(self, vals):
|
||||
"""Inherit packaging from BoM line."""
|
||||
self._packaging_vals_from_bom_line(vals)
|
||||
return super().write(vals)
|
||||
Loading…
Add table
Add a link
Reference in a new issue