Skip to content

Commit

Permalink
redo compute
Browse files Browse the repository at this point in the history
  • Loading branch information
mtwebster committed Mar 28, 2012
1 parent d4b25c7 commit 306e3a3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
53 changes: 53 additions & 0 deletions mrp_operations.py
Expand Up @@ -106,6 +106,8 @@ def _get_date_end(self, cr, uid, ids, field_name, arg, context=None):
readonly=True),
'qty':fields.related('production_id','product_qty',type='float',string='Qty',readonly=True, store=True),
'uom':fields.related('production_id','product_uom',type='many2one',relation='product.uom',string='UOM',readonly=True),
'order_name':fields.text('Description'),
'order_due':fields.date('Due Date'),
}

_defaults = {
Expand Down Expand Up @@ -573,5 +575,56 @@ def initialize_workflow_instance(self, cr, uid, context=None):
}

mrp_operations_operation()



class mrp_production(osv.osv):
_inherit = 'mrp.production'


def action_compute1(self, cr, uid, ids, properties=[], context=None):
""" Computes bills of material of a product.
@param properties: List containing dictionaries of properties.
@return: No. of products.
"""
results = []
bom_obj = self.pool.get('mrp.bom')
uom_obj = self.pool.get('product.uom')
prod_line_obj = self.pool.get('mrp.production.product.line')
workcenter_line_obj = self.pool.get('mrp.production.workcenter.line')
for production in self.browse(cr, uid, ids):
cr.execute('delete from mrp_production_product_line where production_id=%s', (production.id,))
cr.execute('delete from mrp_production_workcenter_line where production_id=%s', (production.id,))
bom_point = production.bom_id
bom_id = production.bom_id.id
if not bom_point:
bom_id = bom_obj._bom_find(cr, uid, production.product_id.id, production.product_uom.id, properties)
if bom_id:
bom_point = bom_obj.browse(cr, uid, bom_id)
routing_id = bom_point.routing_id.id or False
self.write(cr, uid, [production.id], {'bom_id': bom_id, 'routing_id': routing_id})
if not bom_id:
raise osv.except_osv(_('Error'), _("Couldn't find a bill of material for this product."))
factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_point.product_uom.id)
res = bom_obj._bom_explode(cr, uid, bom_point, factor / bom_point.product_qty, properties, routing_id=production.routing_id.id)
results = res[0]
results2 = res[1]
for line in results:
line['production_id'] = production.id
prod_line_obj.create(cr, uid, line)
for line in results2:
line['production_id'] = production.id
line['order_name'] = production.x_order_name
line['order_due'] = production.x_order_due
workcenter_line_obj.create(cr, uid, line)
return len(results)





mrp_production()


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

4 changes: 2 additions & 2 deletions mrp_operations_view.xml
Expand Up @@ -48,8 +48,8 @@
<field name="arch" type="xml">
<tree string="Work Orders" colors="gray:state in ('done','cancel');black:state in ('draft','startworking') and date_planned&gt;=current_date;red:date_planned&lt;current_date and state in ('draft', 'confirmed', 'ready')">
<field name="production_id"/>
<field name="x_order_name"/>
<field name="date_planned"/>
<field name="order_name"/>
<field name="order_due"/>
<field name="product"/>
<field name="qty"/>
<field name="uom"/>
Expand Down

0 comments on commit 306e3a3

Please sign in to comment.