Skip to content

Commit

Permalink
[IMP] mrp_production_deconstruction: pre-commit stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
oihane authored and Tu Nombre committed Jul 2, 2024
1 parent a44d607 commit 72023b8
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 83 deletions.
5 changes: 3 additions & 2 deletions mrp_production_deconstruction/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "MRP Production Deconstruction",
'version': '14.0.1.0.0',
"version": "14.0.1.0.0",
"author": "Avanzosc",
"website": "https://github.com/avanzosc/mrp-addons",
"category": "MRP",
"depends": [
"mrp",
Expand All @@ -13,5 +14,5 @@
"views/mrp_bom_view.xml",
],
"license": "AGPL-3",
'installable': True,
"installable": True,
}
6 changes: 4 additions & 2 deletions mrp_production_deconstruction/models/mrp_bom.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright 2022 Berezi Amubieta - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models, fields
from odoo import fields, models


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

is_deconstruction = fields.Boolean(
string="Is Deconstruction?", default=False)
string="Is Deconstruction?",
default=False,
)
71 changes: 44 additions & 27 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, models, fields
from odoo import api, fields, models


class MrpProduction(models.Model):
Expand All @@ -9,30 +9,33 @@ 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()
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)

def write(self, vals):
res = super(MrpProduction, self).write(vals)
Expand All @@ -46,28 +49,39 @@ 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})
for line in move.move_line_ids:
line.write({
move.write(
{
"location_id": dest.id,
"location_dest_id": origin.id})
"location_dest_id": origin.id,
}
)
for line in move.move_line_ids:
line.write(
{
"location_id": dest.id,
"location_dest_id": origin.id,
}
)

def action_confirm(self):
self._check_is_deconstruction()
Expand All @@ -79,7 +93,10 @@ 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: 6 additions & 14 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, models, fields
from odoo import api, fields, models


class StockMoveLine(models.Model):
Expand Down Expand Up @@ -28,10 +28,8 @@ 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 @@ -42,13 +40,9 @@ 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 @@ -57,7 +51,5 @@ 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: 13 additions & 7 deletions mrp_production_deconstruction/views/mrp_bom_view.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
<?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 72023b8

Please sign in to comment.