[MERGE] purchase: split large method in smaller overridable ones - contribution by Sebastien Beau
On top of the original merge prop by Sebastien, the docstring was completed a bit, and the variable names made more consistent. bzr revid: odo@openerp.com-20110826142836-vzcdop8kzok7toz6
This commit is contained in:
commit
fadcf9160b
|
@ -761,6 +761,23 @@ class procurement_order(osv.osv):
|
|||
res = res.values()
|
||||
return len(res) and res[0] or 0 #TO CHECK: why workflow is generated error if return not integer value
|
||||
|
||||
def create_procurement_purchase_order(self, cr, uid, procurement, po_vals, line_vals, context=None):
|
||||
"""Create the purchase order from the procurement, using
|
||||
the provided field values, after adding the given purchase
|
||||
order line in the purchase order.
|
||||
|
||||
:params procurement: the procurement object generating the purchase order
|
||||
:params dict po_vals: field values for the new purchase order (the
|
||||
``order_line`` field will be overwritten with one
|
||||
single line, as passed in ``line_vals``).
|
||||
:params dict line_vals: field values of the single purchase order line that
|
||||
the purchase order will contain.
|
||||
:return: id of the newly created purchase order
|
||||
:rtype: int
|
||||
"""
|
||||
po_vals.update({'order_line': [(0,0,line_vals)]})
|
||||
return self.pool.get('purchase.order').create(cr, uid, po_vals, context=context)
|
||||
|
||||
def make_po(self, cr, uid, ids, context=None):
|
||||
""" Make purchase order from procurement
|
||||
@return: New created Purchase Orders procurement wise
|
||||
|
@ -774,7 +791,6 @@ class procurement_order(osv.osv):
|
|||
pricelist_obj = self.pool.get('product.pricelist')
|
||||
prod_obj = self.pool.get('product.product')
|
||||
acc_pos_obj = self.pool.get('account.fiscal.position')
|
||||
po_obj = self.pool.get('purchase.order')
|
||||
for procurement in self.browse(cr, uid, ids, context=context):
|
||||
res_id = procurement.move_id.id
|
||||
partner = procurement.product_id.seller_id # Taken Main Supplier of Product of Procurement.
|
||||
|
@ -799,8 +815,10 @@ class procurement_order(osv.osv):
|
|||
context.update({'lang': partner.lang, 'partner_id': partner_id})
|
||||
|
||||
product = prod_obj.browse(cr, uid, procurement.product_id.id, context=context)
|
||||
taxes_ids = procurement.product_id.product_tmpl_id.supplier_taxes_id
|
||||
taxes = acc_pos_obj.map_tax(cr, uid, partner.property_account_position, taxes_ids)
|
||||
|
||||
line = {
|
||||
line_vals = {
|
||||
'name': product.partner_ref,
|
||||
'product_qty': qty,
|
||||
'product_id': procurement.product_id.id,
|
||||
|
@ -809,25 +827,20 @@ class procurement_order(osv.osv):
|
|||
'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'move_dest_id': res_id,
|
||||
'notes': product.description_purchase,
|
||||
'taxes_id': [(6,0,taxes)],
|
||||
}
|
||||
|
||||
taxes_ids = procurement.product_id.product_tmpl_id.supplier_taxes_id
|
||||
taxes = acc_pos_obj.map_tax(cr, uid, partner.property_account_position, taxes_ids)
|
||||
line.update({
|
||||
'taxes_id': [(6,0,taxes)]
|
||||
})
|
||||
purchase_id = po_obj.create(cr, uid, {
|
||||
po_vals = {
|
||||
'origin': procurement.origin,
|
||||
'partner_id': partner_id,
|
||||
'partner_address_id': address_id,
|
||||
'location_id': procurement.location_id.id,
|
||||
'pricelist_id': pricelist_id,
|
||||
'order_line': [(0,0,line)],
|
||||
'company_id': procurement.company_id.id,
|
||||
'fiscal_position': partner.property_account_position and partner.property_account_position.id or False
|
||||
})
|
||||
res[procurement.id] = purchase_id
|
||||
self.write(cr, uid, [procurement.id], {'state': 'running', 'purchase_id': purchase_id})
|
||||
}
|
||||
res[procurement.id] = self.create_procurement_purchase_order(cr, uid, procurement, po_vals, line_vals, context=context)
|
||||
self.write(cr, uid, [procurement.id], {'state': 'running', 'purchase_id': res[procurement.id]})
|
||||
return res
|
||||
|
||||
procurement_order()
|
||||
|
|
Loading…
Reference in New Issue