[IMP] mrp_production_estimated_cost: load estimated cost in creation of Fictitious MO

This commit is contained in:
agaldona
2015-09-11 11:51:59 +02:00
committed by Oihane Crucelaegui
parent 25041631f4
commit 7b779c04b7
4 changed files with 42 additions and 40 deletions

View File

@@ -2,21 +2,21 @@
<openerp>
<data noupdate="1">
<!--Estimated materials analytic journal -->
<record id="analytic_journal_materials" model="account.analytic.journal">
<record id="mrp.analytic_journal_materials" model="account.analytic.journal">
<field name="name">Materials</field>
<field name="code">MAT</field>
<field name="type">general</field>
<field name="active">True</field>
</record>
<!--Estimated operators analytic journal -->
<record id="analytic_journal_operators" model="account.analytic.journal">
<record id="mrp.analytic_journal_operators" model="account.analytic.journal">
<field name="name">Operators</field>
<field name="code">OPE</field>
<field name="type">general</field>
<field name="active">True</field>
</record>
<!--Estimated machines analytic journal -->
<record id="analytic_journal_machines" model="account.analytic.journal">
<record id="mrp.analytic_journal_machines" model="account.analytic.journal">
<field name="name">Machines</field>
<field name="code">MACH</field>
<field name="type">general</field>

View File

@@ -149,9 +149,9 @@ class MrpProduction(models.Model):
}
@api.model
def _prepare_cost_analytic_line(
def _prepare_estimated_cost_analytic_line(
self, journal, name, production, product, general_account=None,
workorder=None, qty=1, std_cost=0, avg_cost=0, amount=0):
workorder=None, qty=1, std_cost=0, avg_cost=0):
"""
Prepare the vals for creating an analytic entry for stimated cost
:param journal: Journal of the entry
@@ -190,7 +190,7 @@ class MrpProduction(models.Model):
'date': analytic_line_obj._get_default_date(),
'product_id': product and product.id or False,
'unit_amount': qty,
'amount': amount,
'amount': 0,
'product_uom_id': product.uom_id.id,
'general_account_id': general_account.id,
'estim_std_cost': -qty * (std_cost or
@@ -203,12 +203,11 @@ class MrpProduction(models.Model):
if not product_line.product_id:
raise exceptions.Warning(
_("One consume line has no product assigned."))
journal = self.env.ref('mrp_production_project_estimated_cost.'
'analytic_journal_materials', False)
journal = self.env.ref('mrp.analytic_journal_materials', False)
name = _('%s-%s' % (prod.name, product_line.work_order.name or ''))
product = product_line.product_id
qty = product_line.product_qty
vals = self._prepare_cost_analytic_line(
vals = self._prepare_estimated_cost_analytic_line(
journal, name, prod, product, workorder=product_line.work_order,
qty=qty)
return self.env['account.analytic.line'].create(vals)
@@ -221,11 +220,10 @@ class MrpProduction(models.Model):
raise exceptions.Warning(
_("Workcenter '%s' doesn't have pre-operation costing "
"product.") % workorder.workcenter_id.name)
journal = self.env.ref('mrp_production_project_estimated_cost.'
'analytic_journal_machines', False)
journal = self.env.ref('mrp.analytic_journal_machines', False)
name = (_('%s-%s Pre-operation') %
(prod.name, workorder.workcenter_id.name))
vals = self._prepare_cost_analytic_line(
vals = self._prepare_estimated_cost_analytic_line(
journal, name, prod, product, workorder=workorder,
qty=wc.time_start)
return self.env['account.analytic.line'].create(vals)
@@ -238,11 +236,10 @@ class MrpProduction(models.Model):
raise exceptions.Warning(
_("Workcenter '%s' doesn't have post-operation costing "
"product.") % workorder.workcenter_id.name)
journal = self.env.ref('mrp_production_project_estimated_cost.'
'analytic_journal_machines', False)
journal = self.env.ref('mrp.analytic_journal_machines', False)
name = (_('%s-%s Post-operation') %
(prod.name, workorder.workcenter_id.name))
vals = self._prepare_cost_analytic_line(
vals = self._prepare_estimated_cost_analytic_line(
journal, name, prod, product, workorder=workorder,
qty=wc.time_stop)
return self.env['account.analytic.line'].create(vals)
@@ -250,8 +247,7 @@ class MrpProduction(models.Model):
@api.model
def _create_worcenter_cycles_estimated_cost(self, prod, wc, workorder):
if workorder.cycle and workorder.workcenter_id.costs_cycle:
journal = prod.env.ref('mrp_production_project_estimated_cost.'
'analytic_journal_machines', False)
journal = prod.env.ref('mrp.analytic_journal_machines', False)
product = workorder.workcenter_id.product_id
if not product:
raise exceptions.Warning(
@@ -261,7 +257,7 @@ class MrpProduction(models.Model):
(prod.name, workorder.routing_wc_line.operation.code,
workorder.workcenter_id.name))
cost = workorder.workcenter_id.costs_cycle
vals = self._prepare_cost_analytic_line(
vals = self._prepare_estimated_cost_analytic_line(
journal, name, prod, product, workorder=workorder,
qty=workorder.cycle, std_cost=cost, avg_cost=cost)
return self.env['account.analytic.line'].create(vals)
@@ -274,13 +270,12 @@ class MrpProduction(models.Model):
raise exceptions.Warning(
_("There is at least this workcenter without "
"product: %s") % workorder.workcenter_id.name)
journal = self.env.ref('mrp_production_project_estimated_cost.'
'analytic_journal_machines', False)
journal = self.env.ref('mrp.analytic_journal_machines', False)
name = (_('%s-%s-H-%s') %
(prod.name, workorder.routing_wc_line.operation.code,
workorder.workcenter_id.name))
cost = workorder.workcenter_id.costs_hour
vals = self._prepare_cost_analytic_line(
vals = self._prepare_estimated_cost_analytic_line(
journal, name, prod, product, workorder=workorder,
qty=workorder.hour, std_cost=cost, avg_cost=cost)
return self.env['account.analytic.line'].create(vals)
@@ -293,15 +288,13 @@ class MrpProduction(models.Model):
raise exceptions.Warning(
_("There is at least this workcenter without "
"product: %s") % workorder.workcenter_id.name)
journal = self.env.ref(
'mrp_production_project_estimated_cost.'
'analytic_journal_operators', False)
journal = self.env.ref('mrp.analytic_journal_operators', False)
name = (_('%s-%s-%s') %
(prod.name, workorder.routing_wc_line.operation.code,
product.name))
cost = wc.op_avg_cost
qty = workorder.hour * wc.op_number
vals = self._prepare_cost_analytic_line(
vals = self._prepare_estimated_cost_analytic_line(
journal, name, prod, product, workorder=workorder, qty=qty,
std_cost=cost, avg_cost=cost)
return self.env['account.analytic.line'].create(vals)

View File

@@ -12,10 +12,21 @@
</field>
</record>
<record id="mrp.mrp_production_form_view_costs" model="ir.ui.view">
<field name="name">mrp.production.form.view.costs</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view"/>
<field name="arch" type="xml">
<page string="Extra Information" position="inside">
<group string="Manufacturing costs">
</group>
</page>
</field>
</record>
<record id="mrp_production_form_view_inh_estimatedcost" model="ir.ui.view">
<field name="name">mrp.production.form.view.inh.estimatedcost</field>
<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_costs"/>
<field name="arch" type="xml">
<button name="button_confirm" position="attributes">
<attribute name="states"></attribute>
@@ -25,20 +36,18 @@
<button name="calculate_production_estimated_cost" states="draft,ready,in_production" string="Create Estimated Costs" type="object"/>
<button name="load_product_std_price" string="Load Cost on Product" type="object" attrs="{'invisible':[('std_cost', '=', 0)]}"/>
</button>
<page string="Extra Information" position="inside">
<group string="Manufacturing costs">
<group>
<field name="std_cost" />
<field name="unit_std_cost" />
<field name="avg_cost" />
<field name="unit_avg_cost" />
</group>
<group>
<field name="product_cost"/>
<field name="product_manual_cost"/>
</group>
<group string="Manufacturing costs" position="inside">
<group>
<field name="std_cost" />
<field name="unit_std_cost" />
<field name="avg_cost" />
<field name="unit_avg_cost" />
</group>
</page>
<group>
<field name="product_cost"/>
<field name="product_manual_cost"/>
</group>
</group>
<xpath expr="//field[@name='product_uom']/.." position="after">
</xpath>
</field>

View File

@@ -52,12 +52,12 @@ class WizCreateFictitiousOf(models.TransientModel):
vals.update(prod_vals)
new_production = production_obj.create(vals)
new_production.action_compute()
new_production.calculate_production_estimated_cost()
production_list.append(new_production.id)
if self.load_on_product:
for production_id in production_list:
try:
production = production_obj.browse(production_id)
production.calculate_production_estimated_cost()
production.load_product_std_price()
except:
continue