[IMP] mrp_production_estimated_cost: manual_standard_cost for variants and not for template + manual cost value for quants

This commit is contained in:
agaldona
2016-05-10 19:09:22 +02:00
parent 20127ddba5
commit b6c8142acb
5 changed files with 55 additions and 16 deletions

View File

@@ -6,7 +6,7 @@
{
"name": "Estimated costs in manufacturing orders",
"version": "8.0.1.1.0",
"version": "8.0.1.2.0",
"category": "Manufacturing",
"author": "OdooMRP team, "
"AvanzOSC, "

View File

@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# © 2016 Ainara Galdona - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
def update_manual_cost(cr):
cr.execute(
"""
UPDATE product_product
SET manual_standard_cost = template.manual_standard_cost
FROM product_template template
WHERE template.id = product_product.product_tmpl_id;
""")
def migrate(cr, version):
if not version:
return
update_manual_cost(cr)

View File

@@ -9,26 +9,30 @@ from openerp import api, exceptions, fields, models, _
class MrpProduction(models.Model):
_inherit = 'mrp.production'
@api.one
@api.multi
@api.depends('analytic_line_ids', 'analytic_line_ids.estim_std_cost',
'product_qty')
def _compute_unit_std_cost(self):
self.std_cost = -sum(self.analytic_line_ids.mapped('estim_std_cost'))
self.unit_std_cost = self.std_cost / self.product_qty
for record in self:
record.std_cost = -sum(record.analytic_line_ids.mapped(
'estim_std_cost'))
record.unit_std_cost = record.std_cost / record.product_qty
@api.one
@api.multi
@api.depends('analytic_line_ids', 'analytic_line_ids.estim_avg_cost',
'product_qty')
def _compute_unit_avg_cost(self):
self.avg_cost = -sum(self.analytic_line_ids.mapped('estim_avg_cost'))
self.unit_avg_cost = self.avg_cost / self.product_qty
for record in self:
record.avg_cost = -sum(record.analytic_line_ids.mapped(
'estim_avg_cost'))
record.unit_avg_cost = record.avg_cost / record.product_qty
@api.one
@api.multi
@api.depends('analytic_line_ids', 'analytic_line_ids.task_id')
def _count_created_estimated_cost(self):
analytic_line_obj = self.env['account.analytic.line']
cond = [('mrp_production_id', '=', self.id),
('task_id', '=', False)]
self.created_estimated_cost = len(analytic_line_obj.search(cond))
for record in self:
record.created_estimated_cost = len(
record.analytic_line_ids.filtered(lambda x: not x.task_id))
active = fields.Boolean(string='Active', default=True)
name = fields.Char(default="/")

View File

@@ -3,7 +3,7 @@
# (c) 2014-2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp import models, fields
from openerp import models, fields, api
import openerp.addons.decimal_precision as dp
@@ -13,3 +13,20 @@ class ProductTemplate(models.Model):
manual_standard_cost = fields.Float(
string='Manual Standard Cost', digits=dp.get_precision('Product Price')
)
class ProductProduct(models.Model):
_inherit = 'product.product'
manual_standard_cost = fields.Float(
string='Manual Standard Cost', digits=dp.get_precision('Product Price')
)
@api.multi
def write(self, vals):
if 'manual_standard_cost' in vals:
templates = self.mapped('product_tmpl_id').filtered(
lambda x: len(x.attribute_line_ids) == 1)
templates.write({'manual_standard_cost':
vals.get('manual_standard_cost')})
return super(ProductProduct, self).write(vals)

View File

@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="product_template_form_view_inh_estimatedcost" model="ir.ui.view">
<field name="name">product.template.form.view.inh.estimatedcost</field>
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">product.template.form.view.estimatedcost</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">