[IMP] purchase: chanded onchange method to create PO line without supplier & pricelist
bzr revid: cha@tinyerp.com-20121018125856-jztpc7nbmkhqr100
This commit is contained in:
+30
-17
@@ -888,16 +888,7 @@ class purchase_order_line(osv.osv):
|
||||
account_fiscal_position = self.pool.get('account.fiscal.position')
|
||||
account_tax = self.pool.get('account.tax')
|
||||
|
||||
# - check for the presence of partner_id and pricelist_id
|
||||
if not pricelist_id:
|
||||
raise osv.except_osv(_('No Pricelist !'), _('Select a price list for a supplier in the purchase form to choose a product.'))
|
||||
if not partner_id:
|
||||
raise osv.except_osv(_('No Supplier!'), _('Select a supplier in purchase order to choose a product.'))
|
||||
|
||||
# - determine name and notes based on product in partner lang.
|
||||
lang = res_partner.browse(cr, uid, partner_id).lang
|
||||
context_partner = {'lang': lang, 'partner_id': partner_id}
|
||||
product = product_product.browse(cr, uid, product_id, context=context_partner)
|
||||
product = product_product.browse(cr, uid, product_id, context=context)
|
||||
name = product.name
|
||||
if product.description_purchase:
|
||||
name += '\n' + product.description_purchase
|
||||
@@ -918,11 +909,36 @@ class purchase_order_line(osv.osv):
|
||||
|
||||
res['value'].update({'product_uom': uom_id})
|
||||
|
||||
# - determine product_qty and date_planned based on seller info
|
||||
qty = qty or 1.0
|
||||
|
||||
if not date_order:
|
||||
date_order = fields.date.context_today(self,cr,uid,context=context)
|
||||
|
||||
qty = qty or 1.0
|
||||
dt = datetime.strptime(date_order, DEFAULT_SERVER_DATE_FORMAT).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
res['value'].update({'date_planned': date_planned or dt, 'product_qty': qty})
|
||||
|
||||
# - determine price_unit and taxes_id
|
||||
price = product.standard_price
|
||||
|
||||
taxes = account_tax.browse(cr, uid, map(lambda x: x.id, product.supplier_taxes_id))
|
||||
fpos = fiscal_position_id and account_fiscal_position.browse(cr, uid, fiscal_position_id, context=context) or False
|
||||
taxes_ids = account_fiscal_position.map_tax(cr, uid, fpos, taxes)
|
||||
res['value'].update({'price_unit': price, 'taxes_id': taxes_ids})
|
||||
|
||||
# - check for the presence of partner_id and pricelist_id
|
||||
if not pricelist_id or not partner_id:
|
||||
return res
|
||||
|
||||
# - determine name and notes based on product in partner lang.
|
||||
lang = res_partner.browse(cr, uid, partner_id).lang
|
||||
context_partner = {'lang': lang, 'partner_id': partner_id}
|
||||
product = product_product.browse(cr, uid, product_id, context=context_partner)
|
||||
name = product.name
|
||||
if product.description_purchase:
|
||||
name += '\n' + product.description_purchase
|
||||
res['value'].update({'name': name})
|
||||
|
||||
# - determine product_qty and date_planned based on seller info
|
||||
supplierinfo = False
|
||||
for supplier in product.seller_ids:
|
||||
if supplier.name.id == partner_id:
|
||||
@@ -938,14 +954,11 @@ class purchase_order_line(osv.osv):
|
||||
|
||||
res['value'].update({'date_planned': date_planned or dt, 'product_qty': qty})
|
||||
|
||||
# - determine price_unit and taxes_id
|
||||
# - determine price_unit according to pricelist
|
||||
price = product_pricelist.price_get(cr, uid, [pricelist_id],
|
||||
product.id, qty or 1.0, partner_id, {'uom': uom_id, 'date': date_order})[pricelist_id]
|
||||
|
||||
taxes = account_tax.browse(cr, uid, map(lambda x: x.id, product.supplier_taxes_id))
|
||||
fpos = fiscal_position_id and account_fiscal_position.browse(cr, uid, fiscal_position_id, context=context) or False
|
||||
taxes_ids = account_fiscal_position.map_tax(cr, uid, fpos, taxes)
|
||||
res['value'].update({'price_unit': price, 'taxes_id': taxes_ids})
|
||||
res['value'].update({'price_unit': price})
|
||||
|
||||
return res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user