Merge PR #607 into 14.0

Signed-off-by dreispt
This commit is contained in:
OCA-git-bot
2021-06-22 17:30:43 +00:00
23 changed files with 142 additions and 14 deletions

View File

@@ -3,15 +3,18 @@
{
"name": "Manufacturing Materials Analytic Costs",
"summary": "Track raw material costs as Analytic Items during the \
manufacturing process",
"summary": "Track manufacturing costs in real time, using Analytic Items",
"version": "14.0.1.0.1",
"category": "Manufacturing",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture",
"license": "AGPL-3",
"depends": ["mrp_analytic"],
"data": ["views/account_analytic_line_view.xml", "views/mrp_production_views.xml"],
"depends": ["mrp_analytic", "analytic_activity_based_cost"],
"data": [
"views/account_analytic_line_view.xml",
"views/mrp_production_views.xml",
"views/mrp_workcenter_view.xml",
],
"maintainer": "dreispt",
"development_status": "Alpha",
"installable": True,

View File

@@ -3,4 +3,5 @@
from . import account_analytic_line
from . import mrp_production
from . import mrp_workorder
from . import stock_move

View File

@@ -7,11 +7,15 @@ from odoo import fields, models
class AccountAnalyticLine(models.Model):
_inherit = "account.analytic.line"
stock_move_id = fields.Many2one(
"stock.move",
string="Related Stock Move",
)
manufacturing_order_id = fields.Many2one(
"mrp.production",
string="Related Manufacturing Order",
)
stock_move_id = fields.Many2one(
"stock.move",
string="Related Stock Move",
)
workorder_id = fields.Many2one(
"mrp.workorder",
string="Work Order",
)

View File

@@ -0,0 +1,78 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class MRPWorkcenter(models.Model):
_inherit = "mrp.workcenter"
@api.depends("analytic_product_id.standard_price")
def _compute_onchange_costs_hour(self):
"""
When using Cost Type Product, set the corresponding standard cost
and the work center hourly cost
"""
for wc in self:
standard_cost = wc.analytic_product_id.standard_price
if standard_cost:
wc.costs_hour = standard_cost
analytic_product_id = fields.Many2one(
"product.product", string="Cost Type", domain="[('is_cost_type', '=', True)]"
)
costs_hour = fields.Float(
compute="_compute_onchange_costs_hour", store=True, readonly=False
)
class MRPWorkorder(models.Model):
_inherit = "mrp.workorder"
def _prepare_mrp_workorder_analytic_item(self):
self.ensure_one()
return {
"name": "{} / {}".format(self.production_id.name, self.name),
"account_id": self.production_id.analytic_account_id.id,
"date": fields.Date.today(),
"company_id": self.company_id.id,
"manufacturing_order_id": self.production_id.id,
"product_id": self.workcenter_id.analytic_product_id.id,
"unit_amount": self.duration / 60, # convert minutes to hours
"workorder_id": self.id,
}
def generate_mrp_work_analytic_line(self):
"""Generate Analytic Lines"""
AnalyticLine = self.env["account.analytic.line"].sudo()
workorders = self.filtered("workcenter_id.analytic_product_id").filtered(
"production_id.analytic_account_id"
)
existing_items = workorders and AnalyticLine.search(
[("workorder_id", "in", self.ids)]
)
for workorder in workorders:
line_vals = self._prepare_mrp_workorder_analytic_item()
analytic_lines = existing_items.filtered(
lambda x: x.workorder_id == workorder
)
if analytic_lines:
for analytic_line in analytic_lines:
analytic_line.write(line_vals)
analytic_line.on_change_unit_amount()
else:
analytic_line = AnalyticLine.create(line_vals)
analytic_line.on_change_unit_amount()
@api.model
def create(self, vals):
res = super().create(vals)
if vals.get("duration"):
res.generate_mrp_work_analytic_line()
return res
def write(self, vals):
res = super().write(vals)
if vals.get("duration"):
self.generate_mrp_work_analytic_line()
return res

View File

@@ -48,6 +48,14 @@ class StockMove(models.Model):
self.generate_mrp_raw_analytic_line()
return res
@api.model
def create(self, vals):
qty_done = vals.get("qty_done")
res = super().create(vals)
if qty_done:
res.generate_mrp_raw_analytic_line()
return res
class StockMoveLine(models.Model):
_inherit = "stock.move.line"

View File

@@ -0,0 +1,3 @@
* Create a Product for each cost type needed. Set the standard cost to use for each of them.
It is also recommended to properly organize them in Product Categories.
* On each Work Center, select the Cost Type Products to use for the operrations generated Analytic Items.

View File

@@ -0,0 +1,12 @@
Out of the box, manufacturing costs are only generated
when a Manufacturing Order is closed.
There are cases where the manufacturing costs need to be tracked in real time.
This is especially important for manufacturing scenarios with a long cycle time,
spanning for multiple months.
This feature allows to track costs while the manufacturing is in progress,
both for raw materials used and work order operations.
Costs incurred are stored as Analytic Items, and can then be analyzed.
No journal entries are generated.

View File

@@ -1,7 +1,10 @@
To use:
* On the Manufacturing Order, set the Analytic Account to use. This may correspond to a Project.
* On Manufacturing Orders, when a stock reservation is triggered, Analytic Items are automatically generated .
* On Manufacturing Orders, Analytic Items are automatically generated when:
* Raw materials are consumed, or
* Time is spent on work order Operations, with a Work Center with a Cost Type product set.
To analyze costs:

View File

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="mrp_workcenter_form_view_custom" model="ir.ui.view">
<field name="name">mrp.workcenter.form.custom</field>
<field name="model">mrp.workcenter</field>
<field name="inherit_id" ref="mrp.mrp_workcenter_view" />
<field name="arch" type="xml">
<field name="costs_hour" position="before">
<field name="analytic_product_id" />
</field>
<field name="costs_hour" position="attributes">
<attribute
name="attrs"
>{"readonly": [("analytic_product_id", "!=", False)]}</attribute>
</field>
</field>
</record>
</odoo>

View File

@@ -1,4 +0,0 @@
Manufacturing costs are only generated when a Manufacturing Order is closed.
This feature allows to track costs while the manufacturing is in progress.
This is done for raw materials used, by generating Analytic Items when the stock is reserved.

View File

@@ -0,0 +1 @@
../../../../mrp_analytic_cost

View File

@@ -1 +0,0 @@
../../../../mrp_analytic_cost_material