Skip to content

Commit

Permalink
[16.0][MIG] mrp_production_deconstruction: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tu Nombre committed Jul 9, 2024
1 parent 72023b8 commit 7bad3c8
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 181 deletions.
2 changes: 1 addition & 1 deletion mrp_production_deconstruction/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
MPR Production Deconstruction
==============================

Deconstruction in production order. If is a deconstruction, it changes the location and the destination location.
Deconstruction in production order. If is a deconstruction, it changes the source location and the destination location.

Bug Tracker
===========
Expand Down
4 changes: 2 additions & 2 deletions mrp_production_deconstruction/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "MRP Production Deconstruction",
"version": "14.0.1.0.0",
'version': '16.0.1.0.0',
"author": "Avanzosc",
"website": "https://github.com/avanzosc/mrp-addons",
"category": "MRP",
Expand All @@ -14,5 +14,5 @@
"views/mrp_bom_view.xml",
],
"license": "AGPL-3",
"installable": True,
'installable': True,
}
6 changes: 2 additions & 4 deletions mrp_production_deconstruction/models/mrp_bom.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Copyright 2022 Berezi Amubieta - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
from odoo import models, fields


class MrpBom(models.Model):
_inherit = "mrp.bom"

is_deconstruction = fields.Boolean(
string="Is Deconstruction?",
default=False,
)
string="Is Deconstruction?", default=False)
74 changes: 29 additions & 45 deletions mrp_production_deconstruction/models/mrp_production.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2022 Berezi Amubieta - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
from odoo import api, models, fields


class MrpProduction(models.Model):
Expand All @@ -9,33 +9,31 @@ class MrpProduction(models.Model):
is_deconstruction = fields.Boolean(
string="Is Deconstruction?",
related="bom_id.is_deconstruction",
store=True,
)
store=True)
move_line_ids = fields.One2many(
string="Move Lines",
comodel_name="stock.move.line",
inverse_name="production_id",
domain=lambda self: [
("location_dest_id", "in", self.production_location_id.ids)
],
)
("location_dest_id", "in", self.production_location_id.ids)],
)
finished_move_line_ids = fields.One2many(
compute=False,
inverse_name="production_id",
domain=lambda self: [
("location_id", "in", self.production_location_id.ids),
("location_dest_id", "in", self.location_dest_id.ids),
],
)
("location_dest_id", "in", self.location_dest_id.ids)],
)

@api.depends("product_id", "company_id", "is_deconstruction")
@api.depends('product_id', 'company_id', "is_deconstruction")
def _compute_production_location(self):
super(MrpProduction, self)._compute_production_location()
result = super(MrpProduction, self)._compute_production_location()
for production in self:
if production.is_deconstruction:
production.production_location_id = (
production.picking_type_id.default_location_src_id.id
) or (False)
production.picking_type_id.default_location_src_id.id) or (
False)
return result

def write(self, vals):
res = super(MrpProduction, self).write(vals)
Expand All @@ -49,39 +47,28 @@ def write(self, vals):

def _check_is_deconstruction(self):
for production in self:
if (
production.bom_id
and production.is_deconstruction is True
and production.move_raw_ids
):
if production.bom_id and (
production.is_deconstruction) is True and (
production.move_raw_ids):
origin = production.picking_type_id.default_location_src_id
if origin.usage != "internal" and (
production.production_location_id.usage == "internal"
):
production.production_location_id.usage) == (
"internal"):
origin = production.production_location_id
dest = production.move_raw_ids.location_dest_id
if dest.usage == "production":
production.write(
{
"location_dest_id": dest.id,
"location_src_id": dest.id,
"production_location_id": origin.id,
}
)
production.write({
"location_dest_id": dest.id,
"location_src_id": dest.id,
"production_location_id": origin.id})
for move in production.move_raw_ids:
move.write(
{
"location_id": dest.id,
"location_dest_id": origin.id,
}
)
move.write({
"location_id": dest.id,
"location_dest_id": origin.id})
for line in move.move_line_ids:
line.write(
{
"location_id": dest.id,
"location_dest_id": origin.id,
}
)
line.write({
"location_id": dest.id,
"location_dest_id": origin.id})

def action_confirm(self):
self._check_is_deconstruction()
Expand All @@ -93,10 +80,7 @@ def button_mark_done(self):
if production.is_deconstruction is True:
origin = production.finished_move_line_ids.location_id
dest = production.finished_move_line_ids.location_dest_id
production.finished_move_line_ids.write(
{
"location_id": dest.id,
"location_dest_id": origin.id,
}
)
production.finished_move_line_ids.write({
"location_id": dest.id,
"location_dest_id": origin.id})
return result
20 changes: 14 additions & 6 deletions mrp_production_deconstruction/models/stock_move_line.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2022 Berezi Amubieta - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
from odoo import _, api, models, fields


class StockMoveLine(models.Model):
Expand Down Expand Up @@ -28,8 +28,10 @@ def _get_default_location_dest_id(self):
result = production.picking_type_id.default_location_src_id.id
return result

location_id = fields.Many2one(default=_get_default_location_id)
location_dest_id = fields.Many2one(default=_get_default_location_dest_id)
location_id = fields.Many2one(
default=_get_default_location_id)
location_dest_id = fields.Many2one(
default=_get_default_location_dest_id)

@api.onchange("location_id", "location_dest_id")
def onchange_product_id_domain(self):
Expand All @@ -40,9 +42,13 @@ def onchange_product_id_domain(self):
[("id", "=", production)], limit=1
)
domain = {}
if production.is_deconstruction is not True and (production.move_raw_ids):
if production.is_deconstruction is not True and (
production.move_raw_ids
):
products = production.move_raw_ids.mapped("product_id")
domain = {"domain": {"product_id": [("id", "in", products.ids)]}}
domain = {"domain": {"product_id": [
("id", "in", products.ids)
]}}
elif "default_production_id" in self.env.context:
production = self.env.context["default_production_id"]
production = self.env["mrp.production"].search(
Expand All @@ -51,5 +57,7 @@ def onchange_product_id_domain(self):
domain = {}
if production.move_byproduct_ids:
products = production.move_byproduct_ids.mapped("product_id")
domain = {"domain": {"product_id": [("id", "in", products.ids)]}}
domain = {"domain": {"product_id": [
("id", "in", products.ids)
]}}
return domain
20 changes: 7 additions & 13 deletions mrp_production_deconstruction/views/mrp_bom_view.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="mrp_bom_form_view" model="ir.ui.view">
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view" />
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
<field name="arch" type="xml">
<field name="company_id" position="before">
<field name="is_deconstruction" />
<field name="is_deconstruction"/>
</field>
<page name="by_products" position="attributes">
<attribute
name="attrs"
>{'invisible': [('is_deconstruction', '=', True)]}</attribute>
<attribute name="attrs">{'invisible': [('is_deconstruction', '=', True)]}</attribute>
</page>
</field>
</record>

<record id="view_mrp_bom_filter" model="ir.ui.view">
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.view_mrp_bom_filter" />
<field name="inherit_id" ref="mrp.view_mrp_bom_filter"/>
<field name="arch" type="xml">
<filter name="inactive" position="before">
<filter
string="Deconstruction"
name="is_deconstruction"
domain="[('is_deconstruction', '=', True)]"
/>
<separator />
<filter string="Deconstruction" name="is_deconstruction" domain="[('is_deconstruction', '=', True)]"/>
<separator/>
</filter>
</field>
</record>
Expand Down
Loading

0 comments on commit 7bad3c8

Please sign in to comment.