Skip to content

Commit

Permalink
[IMP] mrp_production_cost: pre-commit stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
oihane committed Jul 4, 2024
1 parent 0b549db commit 1ff30e2
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 54 deletions.
56 changes: 38 additions & 18 deletions mrp_production_cost/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,43 @@ class MrpProduction(models.Model):

# Material costs
cost_material_to_consume = fields.Float(
string="Cost Material to consume", copy=False, store=True,
compute="_compute_cost_material_to_consume")
string="Cost Material to consume",
copy=False,
store=True,
compute="_compute_cost_material_to_consume",
)
cost_material_consumed = fields.Float(
string="Cost Material consumed", copy=False, store=True,
compute="_compute_cost_material_consumed")
string="Cost Material consumed",
copy=False,
store=True,
compute="_compute_cost_material_consumed",
)
# Workorder costs
cost_workorder_estimated = fields.Float(
string="Cost Workorder estimated", copy=False, store=True,
compute="_compute_cost_workorder_estimated")
string="Cost Workorder estimated",
copy=False,
store=True,
compute="_compute_cost_workorder_estimated",
)
cost_workorder_real = fields.Float(
string="Cost Workorder real", copy=False, store=True,
compute='_compute_cost_workorder_real')
string="Cost Workorder real",
copy=False,
store=True,
compute="_compute_cost_workorder_real",
)
# Manufacturing costs
cost_manufacturing_estimated = fields.Float(
string="Cost Manufacturing estimated", copy=False, store=True,
compute='_compute_cost_manufacturing_estimated')
string="Cost Manufacturing estimated",
copy=False,
store=True,
compute="_compute_cost_manufacturing_estimated",
)
cost_manufacturing_real = fields.Float(
string="Cost Manufacturing real", copy=False, store=True,
compute='_compute_cost_manufacturing_real')
string="Cost Manufacturing real",
copy=False,
store=True,
compute="_compute_cost_manufacturing_real",
)

@api.depends("move_raw_ids.material_cost_to_consume")
def _compute_cost_material_to_consume(self):
Expand All @@ -52,19 +70,21 @@ def _compute_cost_workorder_estimated(self):
@api.depends("workorder_ids.workorder_cost_real")
def _compute_cost_workorder_real(self):
for production in self:
production.cost_workorder_real = (
sum(production.workorder_ids.mapped("workorder_cost_real")))
production.cost_workorder_real = sum(
production.workorder_ids.mapped("workorder_cost_real")
)

@api.depends("cost_material_to_consume", "cost_workorder_estimated")
def _compute_cost_manufacturing_estimated(self):
for production in self:
production.cost_manufacturing_estimated = (
production.cost_material_to_consume +
production.cost_workorder_estimated)
production.cost_material_to_consume
+ production.cost_workorder_estimated
)

@api.depends("cost_material_consumed", "cost_workorder_real")
def _compute_cost_manufacturing_real(self):
for production in self:
production.cost_manufacturing_real = (
production.cost_material_consumed +
production.cost_workorder_real)
production.cost_material_consumed + production.cost_workorder_real
)
32 changes: 21 additions & 11 deletions mrp_production_cost/models/mrp_workorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,33 @@ class MrpWorkorder(models.Model):
_inherit = "mrp.workorder"

machine_hour_cost = fields.Float(
string="Machine hour cost", readonly=True, store=True, copy=False,
related="workcenter_id.costs_hour")
string="Machine hour cost",
readonly=True,
store=True,
copy=False,
related="workcenter_id.costs_hour",
)
workorder_cost_estimated = fields.Float(
string="Workorder Cost estimated", copy=False, store=True,
compute='_compute_workorder_cost_estimated')
string="Workorder Cost estimated",
copy=False,
store=True,
compute="_compute_workorder_cost_estimated",
)
workorder_cost_real = fields.Float(
string="Workorder Cost real", copy=False, store=True,
compute='_compute_workorder_cost_real')
string="Workorder Cost real",
copy=False,
store=True,
compute="_compute_workorder_cost_real",
)

@api.depends('duration_expected', 'machine_hour_cost')
@api.depends("duration_expected", "machine_hour_cost")
def _compute_workorder_cost_estimated(self):
for order in self:
order.workorder_cost_estimated = (
order.machine_hour_cost * order.duration_expected)
order.machine_hour_cost * order.duration_expected
)

@api.depends('duration', 'machine_hour_cost')
@api.depends("duration", "machine_hour_cost")
def _compute_workorder_cost_real(self):
for order in self:
order.workorder_cost_real = (
order.machine_hour_cost * order.duration)
order.workorder_cost_real = order.machine_hour_cost * order.duration
34 changes: 23 additions & 11 deletions mrp_production_cost/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
# Copyright 2022 Patxi Lersundi
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import api, models, fields
from odoo import api, fields, models


class StockMove(models.Model):
_inherit = "stock.move"

product_standard_cost = fields.Float(
string="Standard Cost", readonly=True, store=True, copy=False,
related='product_id.standard_price')
string="Standard Cost",
readonly=True,
store=True,
copy=False,
related="product_id.standard_price",
)
material_cost_to_consume = fields.Float(
string="Material cost to consume", store=True, copy=False,
compute='_compute_material_cost_to_consume')
string="Material cost to consume",
store=True,
copy=False,
compute="_compute_material_cost_to_consume",
)
material_cost_consumed = fields.Float(
string="Material cost consumed", store=True, copy=False,
compute='_compute_material_cost_consumed')
string="Material cost consumed",
store=True,
copy=False,
compute="_compute_material_cost_consumed",
)

@api.depends('product_standard_cost', 'product_uom_qty')
@api.depends("product_standard_cost", "product_uom_qty")
def _compute_material_cost_to_consume(self):
for move in self:
move.material_cost_to_consume = (
move.product_standard_cost * move.product_uom_qty)
move.product_standard_cost * move.product_uom_qty
)

@api.depends('product_standard_cost', 'quantity_done')
@api.depends("product_standard_cost", "quantity_done")
def _compute_material_cost_consumed(self):
for move in self:
move.material_cost_consumed = (
move.product_standard_cost * move.quantity_done)
move.product_standard_cost * move.quantity_done
)
22 changes: 14 additions & 8 deletions mrp_production_cost/views/mrp_production_views.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="mrp_production_form_view" model="ir.ui.view">
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view"/>
<field name="inherit_id" ref="mrp.mrp_production_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='move_raw_ids']/tree/field[@name='product_uom_qty']" position="after">
<field name="product_standard_cost"/>
<field name="material_cost_to_consume"/>
<field name="material_cost_consumed"/>
<xpath
expr="//field[@name='move_raw_ids']/tree/field[@name='product_uom_qty']"
position="after"
>
<field name="product_standard_cost" />
<field name="material_cost_to_consume" />
<field name="material_cost_consumed" />
</xpath>
<field name="material_cost_to_consume" position="attributes">
<attribute name="sum">Cost Material to consume</attribute>
Expand All @@ -22,12 +25,15 @@
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_tree_view" />
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="company_id" position="after">
<field name="cost_material_to_consume" sum="Cost Material to consume" />
<field name="cost_material_consumed" sum="Cost Material consumed" />
<field name="cost_workorder_estimated" sum="Cost Workorder estimated" />
<field name="cost_workorder_real" sum="Cost Workorder real" />
<field name="cost_manufacturing_estimated" sum="Cost Manufacturing estimated" />
<field
name="cost_manufacturing_estimated"
sum="Cost Manufacturing estimated"
/>
<field name="cost_manufacturing_real" sum="Cost Manufacturing real" />
</field>
</field>
Expand Down
4 changes: 2 additions & 2 deletions mrp_production_cost/views/mrp_stockmove_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<field name="inherit_id" ref="stock.view_move_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='company_id']" position="after">
<field name="material_cost_to_consume"/>
<field name="material_cost_consumed"/>
<field name="material_cost_to_consume" />
<field name="material_cost_consumed" />
</xpath>
<field name="material_cost_to_consume" position="attributes">
<attribute name="sum">Material cost to consume</attribute>
Expand Down
11 changes: 7 additions & 4 deletions mrp_production_cost/views/mrp_workorder_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
<odoo>
<record model="ir.ui.view" id="mrp_production_workorder_tree_editable_view">
<field name="model">mrp.workorder</field>
<field name="inherit_id" ref="mrp.mrp_production_workorder_tree_editable_view" />
<field
name="inherit_id"
ref="mrp.mrp_production_workorder_tree_editable_view"
/>
<field name="arch" type="xml">
<xpath expr="//field[@name='duration']" position="after">
<field name="machine_hour_cost"/>
<field name="workorder_cost_estimated"/>
<field name="workorder_cost_real"/>
<field name="machine_hour_cost" />
<field name="workorder_cost_estimated" />
<field name="workorder_cost_real" />
</xpath>
<field name="workorder_cost_estimated" position="attributes">
<attribute name="sum">Workorder Cost estimated</attribute>
Expand Down

0 comments on commit 1ff30e2

Please sign in to comment.