Skip to content

Commit

Permalink
[14.0][IMP] custom_mrp_line_cost: Add no create attribute to lot.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tu Nombre authored and anajuaristi committed Sep 12, 2024
1 parent e62a463 commit 9e32da3
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 7 deletions.
3 changes: 2 additions & 1 deletion custom_mrp_line_cost/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Custom MRP Line Cost",
"version": "14.0.1.0.0",
"version": "14.0.1.1.0",
"category": "MRP",
"license": "AGPL-3",
"author": "AvanzOSC",
Expand All @@ -28,4 +28,5 @@
"views/mrp_routing_workcenter_view.xml",
],
"installable": True,
"pre_init_hook": "pre_init_hook",
}
14 changes: 12 additions & 2 deletions custom_mrp_line_cost/i18n/custom_mrp_line_cost.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-29 11:24+0000\n"
"PO-Revision-Date: 2024-08-29 11:24+0000\n"
"POT-Creation-Date: 2024-09-12 09:08+0000\n"
"PO-Revision-Date: 2024-09-12 09:08+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -152,6 +152,11 @@ msgstr ""
msgid "Dest Kg"
msgstr ""

#. module: custom_mrp_line_cost
#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_production__dif_total_amount
msgid "Dif. Total Amount"
msgstr ""

#. module: custom_mrp_line_cost
#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_killing_cost__display_name
#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_bom__display_name
Expand Down Expand Up @@ -295,6 +300,11 @@ msgstr ""
msgid "October"
msgstr ""

#. module: custom_mrp_line_cost
#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_stock_move_line__operation_id
msgid "Operation"
msgstr ""

#. module: custom_mrp_line_cost
#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_production__origin_qty
msgid "Origin Qty"
Expand Down
14 changes: 12 additions & 2 deletions custom_mrp_line_cost/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-29 11:28+0000\n"
"PO-Revision-Date: 2024-08-29 11:28+0000\n"
"POT-Creation-Date: 2024-09-12 09:08+0000\n"
"PO-Revision-Date: 2024-09-12 09:08+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -152,6 +152,11 @@ msgstr "Diciembre"
msgid "Dest Kg"
msgstr "Cantidad destino"

#. module: custom_mrp_line_cost
#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_production__dif_total_amount
msgid "Dif. Total Amount"
msgstr "Dif. importe"

#. module: custom_mrp_line_cost
#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_killing_cost__display_name
#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_bom__display_name
Expand Down Expand Up @@ -295,6 +300,11 @@ msgstr "Noviembre"
msgid "October"
msgstr "Octubre"

#. module: custom_mrp_line_cost
#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_stock_move_line__operation_id
msgid "Operation"
msgstr "Operación"

#. module: custom_mrp_line_cost
#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_production__origin_qty
msgid "Origin Qty"
Expand Down
31 changes: 31 additions & 0 deletions custom_mrp_line_cost/migrations/14.0.1.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2024 Berezi Amubieta - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging

from openupgradelib import openupgrade

_logger = logging.getLogger(__name__)


@openupgrade.migrate()
def migrate(env, version):
cr = env.cr
if not openupgrade.column_exists(cr, "stock_move_line", "operation_id"):
cr.execute(
"""
ALTER TABLE stock_move_line
ADD COLUMN operation_id integer;
"""
)
cr.execute(
"""
UPDATE stock_move_line
SET operation_id = (SELECT mrp_bom_byproduct.operation_id
FROM mrp_bom_byproduct,
stock_move
WHERE stock_move.id = stock_move_line.move_id
AND move_id IS NOT NULL
AND mrp_bom_byproduct.id = stock_move.byproduct_id
AND byproduct_id IS NOT NULL)
"""
)
17 changes: 15 additions & 2 deletions custom_mrp_line_cost/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,22 @@ class MrpProduction(models.Model):
entry_total_amount = fields.Float(
string="Entry Total Amount", compute="_compute_entry_total_amount", store=True
)
output_total_amount = fields.Float(string="Output Total Amount")
output_total_amount = fields.Float(
string="Output Total Amount", compute="_compute_output_total_amount", store=True
)
consume_qty = fields.Float(
string="Consumed Qty", compute="_compute_consume_qty", store=True
)
dif_total_amount = fields.Float(
string="Dif. Total Amount", compute="_compute_dif_total_amount", store=True
)

@api.depends("entry_total_amount", "output_total_amount")
def _compute_dif_total_amount(self):
for production in self:
production.dif_total_amount = (
production.output_total_amount - production.entry_total_amount
)

@api.depends(
"move_line_ids.qty_done",
Expand All @@ -103,7 +115,7 @@ def _compute_entry_total_amount(self):
for line in self:
entry_total_amount = 0
if line.move_line_ids:
entry_total_amount = sum(self.move_line_ids.mapped("amount"))
entry_total_amount = sum(line.move_line_ids.mapped("amount"))
line.entry_total_amount = entry_total_amount

@api.depends("finished_move_line_ids.amount")
Expand Down Expand Up @@ -263,6 +275,7 @@ def button_calculate_costs(self):
for line in production.finished_move_line_ids:
line.applied_price = line.base_price
line.standard_price = line.applied_price
line.amount = line.standard_price * line.qty_done
dif = (
(production.average_cost + production.month_cost)
* production.consume_qty
Expand Down
8 changes: 8 additions & 0 deletions custom_mrp_line_cost/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def _default_pallet_id(self):
month_cost = fields.Float(
string="Month Cost", compute="_compute_month_cost", store=True
)
operation_id = fields.Many2one(
string="Operation",
comodel_name="mrp.routing.workcenter",
related="move_id.byproduct_id.operation_id",
store=True,
)
pallet_id = fields.Many2one(
string="Pallet",
comodel_name="product.product",
Expand Down Expand Up @@ -187,6 +193,8 @@ def _compute_expense_kg(self):
"production_id.average_cost",
"production_id.month_cost",
"production_id.is_deconstruction",
"production_id.move_line_ids",
"production_id.move_line_ids.amount",
)
def _compute_base_price(self):
for line in self:
Expand Down
1 change: 1 addition & 0 deletions custom_mrp_line_cost/views/stock_move_line_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
attrs="{'readonly': [('tracking', 'not in', ('lot', 'serial'))]}"
context="{'default_product_id': product_id, 'default_company_id': company_id}"
domain="[('product_id', '=', product_id), '|', ('company_id', '=', company_id), ('company_id', '=', False)]"
options="{'no_create': True}"
/>
<field name="location_id" optional="hide" force_save="1" />
<field name="location_dest_id" optional="hide" force_save="1" />
Expand Down

0 comments on commit 9e32da3

Please sign in to comment.