From 90ddcec2d73d2770455b1b6a2eac8cf3c023251c Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Wed, 23 Dec 2009 17:34:53 +0100 Subject: [PATCH] [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 --- addons/account/account_analytic_line.py | 2 +- addons/account/project/project_view.xml | 20 ++++++------ addons/hr_expense/hr_expense.py | 10 ++++-- addons/hr_expense/hr_expense_view.xml | 4 +-- addons/hr_timesheet/hr_timesheet.py | 4 +-- addons/hr_timesheet/hr_timesheet_view.xml | 12 +++---- addons/hr_timesheet/wizard/sign_in_out.py | 2 +- .../hr_timesheet_sheet_view.xml | 8 ++--- addons/project_timesheet/project_timesheet.py | 7 +++- addons/stock/stock.py | 32 +++++++++++++++---- addons/stock/wizard/wizard_partial_move.py | 9 ++++-- 11 files changed, 72 insertions(+), 38 deletions(-) diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index 0abe79f01c6..20ec20f3f32 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -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') diff --git a/addons/account/project/project_view.xml b/addons/account/project/project_view.xml index a730a172f09..dbbfc0cc9c3 100644 --- a/addons/account/project/project_view.xml +++ b/addons/account/project/project_view.xml @@ -163,19 +163,19 @@ tree - + - - + + - + - + @@ -232,16 +232,16 @@
- + - - - + + + - + diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index 4c2ca16ce0c..5064eef8ff1 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -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} diff --git a/addons/hr_expense/hr_expense_view.xml b/addons/hr_expense/hr_expense_view.xml index 184f95a4c3f..3d0e3dde899 100644 --- a/addons/hr_expense/hr_expense_view.xml +++ b/addons/hr_expense/hr_expense_view.xml @@ -58,8 +58,8 @@
- - + + diff --git a/addons/hr_timesheet/hr_timesheet.py b/addons/hr_timesheet/hr_timesheet.py index 1f4f8d2aadb..bf0e0d1426b 100644 --- a/addons/hr_timesheet/hr_timesheet.py +++ b/addons/hr_timesheet/hr_timesheet.py @@ -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): diff --git a/addons/hr_timesheet/hr_timesheet_view.xml b/addons/hr_timesheet/hr_timesheet_view.xml index 976bd64f5fb..0650889f182 100644 --- a/addons/hr_timesheet/hr_timesheet_view.xml +++ b/addons/hr_timesheet/hr_timesheet_view.xml @@ -11,9 +11,9 @@ - - - + + + @@ -29,10 +29,10 @@ - + - - + + diff --git a/addons/hr_timesheet/wizard/sign_in_out.py b/addons/hr_timesheet/wizard/sign_in_out.py index ac2f9d3d5c4..69be06a4b88 100644 --- a/addons/hr_timesheet/wizard/sign_in_out.py +++ b/addons/hr_timesheet/wizard/sign_in_out.py @@ -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 diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml b/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml index a92c6575de9..e0603037b03 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml @@ -118,11 +118,11 @@ - + - + @@ -131,11 +131,11 @@ - + - + diff --git a/addons/project_timesheet/project_timesheet.py b/addons/project_timesheet/project_timesheet.py index 03d463b8269..1dfda98b645 100644 --- a/addons/project_timesheet/project_timesheet.py +++ b/addons/project_timesheet/project_timesheet.py @@ -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) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index afe2ff47ee3..d8873a9e0c7 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -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: diff --git a/addons/stock/wizard/wizard_partial_move.py b/addons/stock/wizard/wizard_partial_move.py index 66e426c1e18..e374c472789 100644 --- a/addons/stock/wizard/wizard_partial_move.py +++ b/addons/stock/wizard/wizard_partial_move.py @@ -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: