1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from openerp.osv import fields, osv
25 class product_template(osv.osv):
26 _inherit = "product.template"
27 def _bom_orders_count(self, cr, uid, ids, field_name, arg, context=None):
28 Bom = self.pool('mrp.bom')
30 for product_tmpl_id in ids:
31 nb = Bom.search_count(cr, uid, [('product_tmpl_id', '=', product_tmpl_id)], context=context)
32 res[product_tmpl_id] = {
37 def _bom_orders_count_mo(self, cr, uid, ids, name, arg, context=None):
39 for product_tmpl_id in self.browse(cr, uid, ids):
40 res[product_tmpl_id.id] = sum([p.mo_count for p in product_tmpl_id.product_variant_ids])
44 'bom_ids': fields.one2many('mrp.bom', 'product_tmpl_id','Bill of Materials'),
45 'bom_count': fields.function(_bom_orders_count, string='# Bill of Material', type='integer', multi="_bom_order_count"),
46 'mo_count': fields.function(_bom_orders_count_mo, string='# Manufacturing Orders', type='integer'),
47 'produce_delay': fields.float('Manufacturing Lead Time', help="Average delay in days to produce this product. In the case of multi-level BOM, the manufacturing lead times of the components will be added."),
48 'track_production': fields.boolean('Track Manufacturing Lots', help="Forces to specify a Serial Number for all moves containing this product and generated by a Manufacturing Order"),
56 def action_view_mos(self, cr, uid, ids, context=None):
57 products = self._get_products(cr, uid, ids, context=context)
58 result = self._get_act_window_dict(cr, uid, 'mrp.act_product_mrp_production', context=context)
59 if len(ids) == 1 and len(products) == 1:
60 result['context'] = "{'default_product_id': " + str(products[0]) + ", 'search_default_product_id': " + str(products[0]) + "}"
62 result['domain'] = "[('product_id','in',[" + ','.join(map(str, products)) + "])]"
63 result['context'] = "{}"
68 class product_product(osv.osv):
69 _inherit = "product.product"
70 def _bom_orders_count(self, cr, uid, ids, field_name, arg, context=None):
71 Production = self.pool('mrp.production')
73 for product_id in ids:
74 res[product_id] = Production.search_count(cr,uid, [('product_id', '=', product_id)], context=context)
78 'mo_count': fields.function(_bom_orders_count, string='# Manufacturing Orders', type='integer'),
81 def action_view_bom(self, cr, uid, ids, context=None):
82 tmpl_obj = self.pool.get("product.template")
84 for product in self.browse(cr, uid, ids, context=context):
85 products.add(product.product_tmpl_id.id)
86 result = tmpl_obj._get_act_window_dict(cr, uid, 'mrp.product_open_bom', context=context)
87 # bom specific to this variant or global to template
90 ('product_id', 'in', ids),
92 ('product_id', '=', False),
93 ('product_tmpl_id', 'in', list(products)),
95 result['context'] = "{}"
96 result['domain'] = str(domain)
99 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: