[FIX]purchase/purchase_requisition: add various fields in tender and forward them to PO when generated from tender, also corrected bug when creating po_line, needs to get description from product _get_name
bzr revid: csn@openerp.com-20130606131026-c61btgakh66pxn0n
This commit is contained in:
parent
accfacfba8
commit
77f8b5f5db
|
@ -933,7 +933,7 @@ class purchase_order_line(osv.osv):
|
|||
|
||||
def onchange_product_uom(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id,
|
||||
partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
|
||||
name=False, price_unit=False, lead_time=False, context=None):
|
||||
name=False, price_unit=False, lead_time=False, state='draft', context=None):
|
||||
"""
|
||||
onchange handler of product_uom.
|
||||
"""
|
||||
|
@ -968,7 +968,7 @@ class purchase_order_line(osv.osv):
|
|||
|
||||
def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id,
|
||||
partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
|
||||
name=False, price_unit=False, lead_time=False, context=None):
|
||||
name=False, price_unit=False, lead_time=False, state='draft', context=None):
|
||||
"""
|
||||
onchange handler of product_id.
|
||||
"""
|
||||
|
@ -1045,13 +1045,13 @@ class purchase_order_line(osv.osv):
|
|||
# - determine lead time value for product
|
||||
product_lead_time = lead_time or supplierinfo.delay if supplierinfo else 0
|
||||
res['value'].update({'product_lead_time': product_lead_time})
|
||||
|
||||
# - determine price_unit and taxes_id
|
||||
if pricelist_id:
|
||||
price = product_pricelist.price_get(cr, uid, [pricelist_id],
|
||||
product.id, qty or 1.0, partner_id or False, {'uom': uom_id, 'date': date_order})[pricelist_id]
|
||||
else:
|
||||
price = product.standard_price
|
||||
if state not in ('sent','bid'):
|
||||
# - determine price_unit and taxes_id
|
||||
if pricelist_id:
|
||||
price = product_pricelist.price_get(cr, uid, [pricelist_id],
|
||||
product.id, qty or 1.0, partner_id or False, {'uom': uom_id, 'date': date_order})[pricelist_id]
|
||||
else:
|
||||
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
|
||||
|
|
|
@ -206,14 +206,14 @@
|
|||
<page string="Products">
|
||||
<field name="order_line">
|
||||
<tree string="Purchase Order Lines" editable="bottom">
|
||||
<field name="product_id" on_change="onchange_product_id(parent.pricelist_id,product_id,0,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,context)"/>
|
||||
<field name="product_id" on_change="onchange_product_id(parent.pricelist_id,product_id,0,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,parent.state,context)"/>
|
||||
<field name="name"/>
|
||||
<field name="date_planned"/>
|
||||
<field name="product_lead_time" on_change="onchange_product_id(parent.pricelist_id,product_id,0,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit, product_lead_time, context)" />
|
||||
<field name="product_lead_time" on_change="onchange_product_id(parent.pricelist_id,product_id,0,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit, product_lead_time,parent.state, context)" />
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
<field name="account_analytic_id" groups="purchase.group_analytic_accounting" domain="[('type','not in',('view','template'))]"/>
|
||||
<field name="product_qty" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id,parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,context)"/>
|
||||
<field name="product_uom" groups="product.group_uom" on_change="onchange_product_uom(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,context)"/>
|
||||
<field name="product_qty" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id,parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,parent.state,context)"/>
|
||||
<field name="product_uom" groups="product.group_uom" on_change="onchange_product_uom(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,parent.state,context)"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="taxes_id" widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','!=','sale')]"/>
|
||||
<field name="price_subtotal"/>
|
||||
|
@ -393,11 +393,11 @@
|
|||
<sheet>
|
||||
<group>
|
||||
<group>
|
||||
<field name="product_id" on_change="onchange_product_id(parent.pricelist_id,product_id,0,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,context)"/>
|
||||
<field name="product_id" on_change="onchange_product_id(parent.pricelist_id,product_id,0,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,'draft',context)"/>
|
||||
<label for="product_qty"/>
|
||||
<div>
|
||||
<field name="product_qty" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id,parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,context)" class="oe_inline"/>
|
||||
<field name="product_uom" groups="product.group_uom" on_change="onchange_product_uom(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,context)" class="oe_inline"/>
|
||||
<field name="product_qty" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id,parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,'draft',context)" class="oe_inline"/>
|
||||
<field name="product_uom" groups="product.group_uom" on_change="onchange_product_uom(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,product_lead_time,'draft',context)" class="oe_inline"/>
|
||||
</div>
|
||||
<field name="price_unit"/>
|
||||
</group>
|
||||
|
|
|
@ -61,6 +61,7 @@ class purchase_requisition(osv.osv):
|
|||
'Status', track_visibility='onchange', required=True),
|
||||
'multiple_rfq_per_supplier': fields.boolean('Multiple RFQ per supplier'),
|
||||
'account_analytic_id':fields.many2one('account.analytic.account', 'Analytic Account',),
|
||||
'schedule_date': fields.date('Scheduled Date', select=True),
|
||||
}
|
||||
_defaults = {
|
||||
'date_start': lambda *args: time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
|
@ -170,6 +171,7 @@ class purchase_requisition(osv.osv):
|
|||
supplier_pricelist = supplier.property_product_pricelist_purchase or False
|
||||
return {
|
||||
'origin': requisition.name,
|
||||
'order_date': requisition.date_end or fields.date.context_today,
|
||||
'partner_id': supplier.id,
|
||||
'pricelist_id': supplier_pricelist.id,
|
||||
'location_id': location_id,
|
||||
|
@ -181,20 +183,32 @@ class purchase_requisition(osv.osv):
|
|||
}
|
||||
def _prepare_purchase_order_line(self, cr, uid, requisition, requisition_line, purchase_id, supplier, context=None):
|
||||
fiscal_position = self.pool.get('account.fiscal.position')
|
||||
res_partner = self.pool.get('res.partner')
|
||||
product_product = self.pool.get('product.product')
|
||||
product = requisition_line.product_id
|
||||
seller_price, qty, default_uom_po_id, date_planned = self._seller_details(cr, uid, requisition_line, supplier, context=context)
|
||||
taxes_ids = product.supplier_taxes_id
|
||||
taxes = fiscal_position.map_tax(cr, uid, supplier.property_account_position, taxes_ids)
|
||||
# - determine name and notes based on product in partner lang.
|
||||
context_partner = context.copy()
|
||||
|
||||
if supplier:
|
||||
lang = res_partner.browse(cr, uid, supplier.id).lang
|
||||
context_partner.update( {'lang': lang, 'partner_id': supplier.id} )
|
||||
#call name_get() with partner in the context to eventually match name and description in the seller_ids field
|
||||
dummy, name = product_product.name_get(cr, uid, product.id, context=context_partner)[0]
|
||||
if product.description_purchase:
|
||||
name += '\n' + product.description_purchase
|
||||
return {
|
||||
'order_id': purchase_id,
|
||||
'name': product.partner_ref,
|
||||
'name': name,
|
||||
'product_qty': qty,
|
||||
'product_id': product.id,
|
||||
'product_uom': default_uom_po_id,
|
||||
'price_unit': seller_price,
|
||||
'date_planned': date_planned,
|
||||
'date_planned': requisition_line.schedule_date,
|
||||
'taxes_id': [(6, 0, taxes)],
|
||||
'account_analytic_id':requisition.account_analytic_id.id,
|
||||
'account_analytic_id':requisition_line.account_analytic_id.id,
|
||||
}
|
||||
def make_purchase_order(self, cr, uid, ids, partner_id, context=None):
|
||||
"""
|
||||
|
@ -314,9 +328,11 @@ class purchase_requisition_line(osv.osv):
|
|||
'requisition_id': fields.many2one('purchase.requisition','Purchase Requisition', ondelete='cascade'),
|
||||
'po_line_ids': fields.related('requisition_id', 'po_line_ids', string='PO lines', readonly=True, type="one2many"),
|
||||
'company_id': fields.related('requisition_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True),
|
||||
'account_analytic_id':fields.many2one('account.analytic.account', 'Analytic Account',),
|
||||
'schedule_date': fields.date('Scheduled Date', select=True),
|
||||
}
|
||||
|
||||
def onchange_product_id(self, cr, uid, ids, product_id, product_uom_id, context=None):
|
||||
def onchange_product_id(self, cr, uid, ids, product_id, product_uom_id, parent_analytic_account, analytic_account, parent_date, date, context=None):
|
||||
""" Changes UoM and name if product_id changes.
|
||||
@param name: Name of the field
|
||||
@param product_id: Changed product_id
|
||||
|
@ -326,6 +342,10 @@ class purchase_requisition_line(osv.osv):
|
|||
if product_id:
|
||||
prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
|
||||
value = {'product_uom_id': prod.uom_id.id,'product_qty':1.0}
|
||||
if not analytic_account:
|
||||
value.update({'account_analytic_id': parent_analytic_account})
|
||||
if not date:
|
||||
value.update({'schedule_date': parent_date})
|
||||
return {'value': value}
|
||||
|
||||
_defaults = {
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
<group>
|
||||
<field name="date_start"/>
|
||||
<field name="date_end"/>
|
||||
<field name="schedule_date"/>
|
||||
<field name="origin" placeholder="e.g. PO0025"/>
|
||||
<field name="warehouse_id" widget="selection" groups="stock.group_locations"/>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
|
@ -68,15 +69,20 @@
|
|||
<page string="Products">
|
||||
<field name="line_ids">
|
||||
<tree string="Products" editable="bottom">
|
||||
<field name="product_id" on_change="onchange_product_id(product_id,product_uom_id)"/>
|
||||
<field name="product_id" on_change="onchange_product_id(product_id,product_uom_id,parent.account_analytic_id,account_analytic_id,parent.schedule_date,schedule_date)"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom_id" groups="product.group_uom"/>
|
||||
<field name="schedule_date"/>
|
||||
<field name="account_analytic_id" groups="purchase.group_analytic_accounting"/>
|
||||
|
||||
</tree>
|
||||
<form string="Products" version="7.0">
|
||||
<group>
|
||||
<field name="product_id" />
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom_id" />
|
||||
<field name="schedule_date"/>
|
||||
<field name="account_analytic_id" groups="purchase.group_analytic_accounting"/>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
</group>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue