diff --git a/mrp_production_estimated_cost/__openerp__.py b/mrp_production_estimated_cost/__openerp__.py index b1f33901d..b337ec9b7 100644 --- a/mrp_production_estimated_cost/__openerp__.py +++ b/mrp_production_estimated_cost/__openerp__.py @@ -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, " diff --git a/mrp_production_estimated_cost/migrations/8.0.1.2.0/post-migration.py b/mrp_production_estimated_cost/migrations/8.0.1.2.0/post-migration.py new file mode 100644 index 000000000..be74d413b --- /dev/null +++ b/mrp_production_estimated_cost/migrations/8.0.1.2.0/post-migration.py @@ -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) diff --git a/mrp_production_estimated_cost/models/mrp_production.py b/mrp_production_estimated_cost/models/mrp_production.py index 1ca9180d1..1a7ccdbaf 100644 --- a/mrp_production_estimated_cost/models/mrp_production.py +++ b/mrp_production_estimated_cost/models/mrp_production.py @@ -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="/") diff --git a/mrp_production_estimated_cost/models/product.py b/mrp_production_estimated_cost/models/product.py index c34cc694f..21dff8497 100644 --- a/mrp_production_estimated_cost/models/product.py +++ b/mrp_production_estimated_cost/models/product.py @@ -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) diff --git a/mrp_production_estimated_cost/views/product_view.xml b/mrp_production_estimated_cost/views/product_view.xml index 6b8180e02..c4fe452a8 100644 --- a/mrp_production_estimated_cost/views/product_view.xml +++ b/mrp_production_estimated_cost/views/product_view.xml @@ -1,9 +1,8 @@ - - - product.template.form.view.inh.estimatedcost + + product.template.form.view.estimatedcost product.template