[API] Remove date from onchange_unit_amount from analytic line, cause they are no more used as we base computation on pricetype

[FIX] Start to replace standard_price in everymodule with the right field according to company property

bzr revid: joel.grandguillaume@camptocamp.com-20091223163453-1a1y2pu9kmrzbep4
This commit is contained in:
Joel Grand-Guillaume 2009-12-23 17:34:53 +01:00
parent 0793892ca4
commit 90ddcec2d7
11 changed files with 72 additions and 38 deletions

View File

@ -125,7 +125,7 @@ class account_analytic_line(osv.osv):
# Compute the cost based on the price type define into company
# property_valuation_price_type property
def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount,company_id,
date,unit=False, context=None):
unit=False, context=None):
if context==None:
context={}
uom_obj = self.pool.get('product.uom')

View File

@ -163,19 +163,19 @@
<field name="type">tree</field>
<field name="arch" type="xml">
<tree editable="top" string="Analytic Entries">
<field name="date" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)"/>
<field name="date" on_change="on_change_unit_amount(product_id, unit_amount, company_id, product_uom_id)"/>
<field name="name"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)" sum="Total quantity"/>
<field name="product_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, company_id, product_uom_id)" sum="Total quantity"/>
<field name="product_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id, product_uom_id)"/>
<field domain="[('type','=','normal')]" name="account_id"/>
<field invisible="True" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)"/>
<field invisible="True" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id, product_uom_id)"/>
<field name="amount" sum="Total amount"/>
<field name="general_account_id"/>
<field name="journal_id"/>
<field name="ref"/>
<field name="currency_id" />
<field name="amount_currency" />
<field name="company_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)"/>
<field name="company_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id, product_uom_id)"/>
</tree>
</field>
</record>
@ -232,16 +232,16 @@
<form string="Project line">
<field name="name"/>
<field name="account_id"/>
<field name="date" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)"/>
<field name="date" on_change="on_change_unit_amount(product_id, unit_amount, company_id, product_uom_id)"/>
<field name="journal_id"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)"/>
<field name="product_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)"/>
<field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, company_id, product_uom_id)"/>
<field name="product_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id, product_uom_id)"/>
<field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id, product_uom_id)"/>
<field invisible="True" name="general_account_id"/>
<field name="amount"/>
<field name="currency_id" />
<field name="amount_currency" />
<field name="company_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)"/>
<field name="company_id" on_change="on_change_unit_amount(product_id, unit_amount, company_id, product_uom_id)"/>
</form>
</field>
</record>

View File

@ -212,12 +212,18 @@ class hr_expense_line(osv.osv):
'date_value' : lambda *a: time.strftime('%Y-%m-%d'),
}
_order = "sequence"
def onchange_product_id(self, cr, uid, ids, product_id, uom_id, context={}):
def onchange_product_id(self, cr, uid, ids, product_id, uom_id, employee_id, context={}):
v={}
if product_id:
product=self.pool.get('product.product').browse(cr,uid,product_id, context=context)
v['name']=product.name
v['unit_amount']=product.standard_price
# Compute based on pricetype of employee company
pricetype_id = self.pool.get('hr.employee').browse(cr,uid,employee_id).user_id.company_id.property_valuation_price_type.id
pricetype=self.pool.get('product.price.type').browse(cr,uid,pricetype_id)
amount_unit=product.price_get(pricetype.field, context)[product.id]
v['unit_amount']=amount_unit
if not uom_id:
v['uom_id']=product.uom_id.id
return {'value':v}

View File

@ -58,8 +58,8 @@
<newline/>
<field colspan="4" name="line_ids" nolabel="1">
<form string="Expense Lines">
<field name="product_id" on_change="onchange_product_id(product_id, uom_id)" select="2"/>
<field name="uom_id" on_change="onchange_product_id(product_id, uom_id)" select="2"/>
<field name="product_id" on_change="onchange_product_id(product_id, uom_id, parent.employee_id)" select="2"/>
<field name="uom_id" on_change="onchange_product_id(product_id, uom_id, parent.employee_id)" select="2"/>
<field name="name" select="1"/>
<field name="date_value" select="1"/>
<field name="unit_quantity" select="2"/>

View File

@ -53,13 +53,13 @@ class hr_analytic_timesheet(osv.osv):
return super(hr_analytic_timesheet, self).unlink(cr, uid, ids, context)
def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount, date, unit, context={}):
def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount, unit, context={}):
res = {}
# if prod_id and unit_amount:
if prod_id and date:
# find company
company_id=self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context)
res = self.pool.get('account.analytic.line').on_change_unit_amount(cr, uid, id, prod_id, unit_amount,company_id,date,unit, context)
res = self.pool.get('account.analytic.line').on_change_unit_amount(cr, uid, id, prod_id, unit_amount,company_id,unit, context)
return res
def _getEmployeeProduct(self, cr, uid, context):

View File

@ -11,9 +11,9 @@
<field name="date" on_change="on_change_date(date)"/>
<field domain="[('type','=','normal'),('state', '&lt;&gt;', 'close')]" name="account_id"/>
<field name="name"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount,date, product_uom_id)" sum="Total time"/>
<field name="product_id" on_change="on_change_unit_amount(product_id, unit_amount, date, product_uom_id)" required="1" domain="[('type','=','service')]"/>
<field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, date, product_uom_id)"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)" sum="Total time"/>
<field name="product_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)" required="1" domain="[('type','=','service')]"/>
<field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
<field name="amount" sum="Total cost"/>
<field name="general_account_id"/>
<field name="journal_id"/>
@ -29,10 +29,10 @@
<field colspan="4" name="name" select="2"/>
<field name="user_id" on_change="on_change_user_id(user_id)" required="1" select="1"/>
<field name="date" select="1" on_change="on_change_date(date)"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, date, product_uom_id)"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
<newline/>
<field name="product_id" on_change="on_change_unit_amount(product_id, unit_amount, date, product_uom_id)" required="1" domain="[('type','=','service')]"/>
<field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, date, product_uom_id)"/>
<field name="product_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)" required="1" domain="[('type','=','service')]"/>
<field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
<field domain="[('type','=','normal'),('state', '&lt;&gt;', 'close')]" name="account_id" select="1"/>
<field name="amount" select="2"/>

View File

@ -106,7 +106,7 @@ def _write(self, cr, uid, data, emp_id, context):
res = timesheet_obj.default_get(cr, uid, ['product_id','product_uom_id'])
if not res['product_uom_id']:
raise wizard.except_wizard(_('UserError'), _('No cost unit defined for this employee !'))
up = timesheet_obj.on_change_unit_amount(cr, uid, False, res['product_id'], hour, data['form']['date'], res['product_uom_id'])['value']
up = timesheet_obj.on_change_unit_amount(cr, uid, False, res['product_id'], hour, res['product_uom_id'])['value']
res['name'] = data['form']['info']
res['account_id'] = data['form']['account_id']
res['unit_amount'] = hour

View File

@ -118,11 +118,11 @@
<field invisible="1" name="date"/>
<field domain="[('type','=','normal'), ('state', '&lt;&gt;', 'close')]" name="account_id" on_change="on_change_account_id(account_id)"/>
<field name="name"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, date, product_uom_id)" widget="float_time"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)" widget="float_time"/>
<field name="to_invoice"/>
<field invisible="1" name="journal_id"/>
<field invisible="1" name="product_id"/>
<field invisible="1" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, date, product_uom_id)"/>
<field invisible="1" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
<field name="amount"/>
<field name="general_account_id"/>
<field invisible="1" name="user_id" required="1"/>
@ -131,11 +131,11 @@
<field name="date"/>
<field domain="[('type','=','normal'), ('state', '&lt;&gt;', 'close')]" name="account_id" on_change="on_change_account_id(account_id)"/>
<field name="name"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, date, product_uom_id)" widget="float_time"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)" widget="float_time"/>
<field name="to_invoice"/>
<field invisible="1" name="journal_id"/>
<field invisible="1" name="product_id"/>
<field invisible="1" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, date, product_uom_id)"/>
<field invisible="1" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
<field name="amount"/>
<field name="general_account_id"/>
<field name="user_id" required="1"/>

View File

@ -104,7 +104,12 @@ class project_work(osv.osv):
vals_line['date'] = vals['date'][:10]
if 'hours' in vals:
vals_line['unit_amount'] = vals['hours']
vals_line['amount'] = (-1) * vals['hours'] * (obj.browse(cr,uid,line_id).product_id.standard_price or 0.0)
# Compute based on pricetype
amount_unit=obj.on_change_unit_amount(cr, uid, line_id,
vals_line['product_id'], vals_line['unit_amount'], unit, context)
vals_line['amount'] = (-1) * vals['hours'] * (amount_unit or 0.0)
obj.write(cr, uid, [line_id], vals_line, {})
return super(project_work,self).write(cr, uid, ids, vals, context)

View File

@ -110,11 +110,15 @@ class stock_location(osv.osv):
cr.execute('select distinct product_id from stock_move where (location_id=%s) or (location_dest_id=%s)', (id, id))
result = cr.dictfetchall()
if result:
# Choose the right filed standard_price to read
# Take the user company
price_type_id=self.pool.get('res.users').browse(cr,uid,uid).company_id.property_valuation_price_type.id
pricetype=self.pool.get('product.price.type').browse(cr,uid,price_type_id)
for r in result:
c = (context or {}).copy()
c['location'] = id
product = self.pool.get('product.product').read(cr, uid, r['product_id'], [field_to_read, 'standard_price'], context=c)
final_value += (product[field_to_read] * product['standard_price'])
product = self.pool.get('product.product').read(cr, uid, r['product_id'], [field_to_read, pricetype.field], context=c)
final_value += (product[field_to_read] * product[pricetype.field])
return final_value
def _product_value(self, cr, uid, ids, field_names, arg, context={}):
@ -211,6 +215,10 @@ class stock_location(osv.osv):
if context is None:
context = {}
product_obj = self.pool.get('product.product')
# Take the user company and pricetype
price_type_id=self.pool.get('res.users').browse(cr,uid,uid).company_id.property_valuation_price_type.id
pricetype=self.pool.get('product.price.type').browse(cr,uid,price_type_id)
if not product_ids:
product_ids = product_obj.search(cr, uid, [])
@ -241,10 +249,16 @@ class stock_location(osv.osv):
continue
product = products_by_id[product_id]
quantity_total += qty[product_id]
price = qty[product_id] * product.standard_price
# Compute based on pricetype
# Choose the right filed standard_price to read
amount_unit=product.price_get(pricetype.field, context)[product.id]
price = qty[product_id] * amount_unit
# price = qty[product_id] * product.standard_price
total_price += price
result['product'].append({
'price': product.standard_price,
'price': amount_unit,
'prod_name': product.name,
'code': product.default_code, # used by lot_overview_all report!
'variants': product.variants or '',
@ -645,7 +659,12 @@ class stock_picking(osv.osv):
def _get_price_unit_invoice(self, cursor, user, move_line, type):
'''Return the price unit for the move line'''
if type in ('in_invoice', 'in_refund'):
return move_line.product_id.standard_price
# Take the user company and pricetype
price_type_id=self.pool.get('res.users').browse(cr,users,users).company_id.property_valuation_price_type.id
pricetype=self.pool.get('product.price.type').browse(cr,uid,price_type_id)
amount_unit=move_line.product_id.price_get(pricetype.field, context)[move_line.product_id.id]
return amount_unit
# return move_line.product_id.standard_price
else:
return move_line.product_id.list_price
@ -1411,7 +1430,8 @@ class stock_inventory(osv.osv):
move_line = []
for line in inv.inventory_line_id:
pid = line.product_id.id
price = line.product_id.standard_price or 0.0
# price = line.product_id.standard_price or 0.0
amount = self.pool.get('stock.location')._product_get(cr, uid, line.location_id.id, [pid], {'uom': line.product_uom.id})[pid]
change = line.product_qty - amount
if change:

View File

@ -124,7 +124,8 @@ def _do_split(self, cr, uid, data, context):
currency = data['form']['currency%s' % move.id]
qty = uom_obj._compute_qty(cr, uid, uom, qty, product.uom_id.id)
pricetype=pool.get('product.price.type').browse(cr,uid,user.company_id.property_valuation_price_type.id)
if (qty > 0):
new_price = currency_obj.compute(cr, uid, currency,
user.company_id.currency_id.id, price)
@ -133,11 +134,13 @@ def _do_split(self, cr, uid, data, context):
if product.qty_available<=0:
new_std_price = new_price
else:
new_std_price = ((product.standard_price * product.qty_available)\
# Get the standard price
amount_unit=product.price_get(pricetype.field, context)[product.id]
new_std_price = ((product.amount_unit * product.qty_available)\
+ (new_price * qty))/(product.qty_available + qty)
product_obj.write(cr, uid, [product.id],
{'standard_price': new_std_price})
{pricetype.field: new_std_price})
move_obj.write(cr, uid, move.id, {'price_unit': new_price})
for move in too_few: