diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index 40af2ba7ed2..08f36f65e53 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -25,10 +25,46 @@ from osv import fields from osv import osv from tools.translate import _ import tools +from tools import config class account_analytic_line(osv.osv): _name = 'account.analytic.line' _description = 'Analytic lines' + + def _amount_currency(self, cr, uid, ids, field_name, arg, context={}): + result = {} + for rec in self.browse(cr, uid, ids, context): + cmp_cur_id=rec.company_id.currency_id.id + aa_cur_id=rec.account_id.currency_id.id + # Always provide the amount in currency + if cmp_cur_id != aa_cur_id: + cur_obj = self.pool.get('res.currency') + ctx = {} + if rec.date and rec.amount: + ctx['date'] = rec.date + result[rec.id] = cur_obj.compute(cr, uid, rec.company_id.currency_id.id, + rec.account_id.currency_id.id, rec.amount, + context=ctx) + else: + result[rec.id]=rec.amount + return result + + def _get_account_currency(self, cr, uid, ids, field_name, arg, context={}): + result = {} + for rec in self.browse(cr, uid, ids, context): + # Always provide second currency + result[rec.id] = (rec.account_id.currency_id.id,rec.account_id.currency_id.code) + return result + + def _get_account_line(self, cr, uid, ids, context={}): + aac_ids = {} + for acc in self.pool.get('account.analytic.account').browse(cr, uid, ids): + aac_ids[acc.id] = True + aal_ids = [] + if aac_ids: + aal_ids = self.pool.get('account.analytic.line').search(cr, uid, [('account_id','in',aac_ids.keys())], context=context) + return aal_ids + _columns = { 'name' : fields.char('Description', size=256, required=True), 'date' : fields.date('Date', required=True), @@ -42,14 +78,27 @@ class account_analytic_line(osv.osv): 'journal_id' : fields.many2one('account.analytic.journal', 'Analytic Journal', required=True, ondelete='cascade', select=True), 'code' : fields.char('Code', size=8), 'user_id' : fields.many2one('res.users', 'User',), + 'currency_id': fields.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Account currency', + store={ + 'account.analytic.account': (_get_account_line, ['company_id'], 50), + 'account.analytic.line': (lambda self,cr,uid,ids,c={}: ids, ['amount','unit_amount'],10), + }, + help="The related account currency if not equal to the company one."), + 'company_id': fields.many2one('res.company','Company',required=True), + 'amount_currency': fields.function(_amount_currency, method=True, digits=(16, int(config['price_accuracy'])), string='Amount currency', + store={ + 'account.analytic.account': (_get_account_line, ['company_id'], 50), + 'account.analytic.line': (lambda self,cr,uid,ids,c={}: ids, ['amount','unit_amount'],10), + }, + help="The amount expressed in the related account currency if not equal to the company one."), 'ref': fields.char('Reference', size=32), } _defaults = { 'date': lambda *a: time.strftime('%Y-%m-%d'), + 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', c), } _order = 'date' - def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): if context is None: context = {} @@ -73,11 +122,15 @@ class account_analytic_line(osv.osv): # (_check_company, 'You can not create analytic line that is not in the same company than the account line', ['account_id']) ] - def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount, + # 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, unit=False, context=None): + if context==None: + context={} uom_obj = self.pool.get('product.uom') product_obj = self.pool.get('product.product') -# if unit_amount and prod_id: + company_obj=self.pool.get('res.company') if prod_id: prod = product_obj.browse(cr, uid, prod_id) a = prod.product_tmpl_id.property_account_expense.id @@ -88,8 +141,14 @@ class account_analytic_line(osv.osv): _('There is no expense account defined ' \ 'for this product: "%s" (id:%d)') % \ (prod.name, prod.id,)) - amount = unit_amount * uom_obj._compute_price(cr, uid, - prod.uom_id.id, prod.standard_price, unit) + if not company_id: + company_id=company_obj._company_default_get(cr, uid, 'account.analytic.line', context) + + # Compute based on pricetype + pricetype=self.pool.get('product.price.type').browse(cr,uid,company_obj.browse(cr,uid,company_id).property_valuation_price_type.id) + amount_unit=prod.price_get(pricetype.field, context)[prod.id] + + amount=amount_unit*unit_amount or 1.0 return {'value': { 'amount': - round(amount, 2), 'general_account_id': a, diff --git a/addons/account/project/project.py b/addons/account/project/project.py index 7ad98b04b32..a844d6dec2e 100644 --- a/addons/account/project/project.py +++ b/addons/account/project/project.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). +# Copyright (C) 2004-2009 Tiny SPRL (). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## @@ -25,10 +25,6 @@ import operator from osv import fields from osv import osv -# -# Object definition -# - class account_analytic_journal(osv.osv): _name = 'account.analytic.journal' _columns = { diff --git a/addons/account/project/project_view.xml b/addons/account/project/project_view.xml index 1123b122eaf..a2be8716c1e 100644 --- a/addons/account/project/project_view.xml +++ b/addons/account/project/project_view.xml @@ -69,6 +69,7 @@ + @@ -147,6 +148,9 @@ + + + @@ -159,16 +163,19 @@ tree - + - - + + - + + + + @@ -225,13 +232,16 @@
- + - - - + + + + + + diff --git a/addons/account_analytic_analysis/account_analytic_analysis.py b/addons/account_analytic_analysis/account_analytic_analysis.py index 549d6aa06e1..7e4807a3f81 100644 --- a/addons/account_analytic_analysis/account_analytic_analysis.py +++ b/addons/account_analytic_analysis/account_analytic_analysis.py @@ -34,7 +34,8 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - cr.execute("select account_analytic_line.account_id, COALESCE(sum(amount),0.0) \ + acc_set = ",".join(map(str, ids2)) + cr.execute("select account_analytic_line.account_id, COALESCE(sum(amount_currency),0.0) \ from account_analytic_line \ join account_analytic_journal \ on account_analytic_line.journal_id = account_analytic_journal.id \ @@ -43,15 +44,8 @@ class account_analytic_account(osv.osv): group by account_analytic_line.account_id" ,(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = round(sum,2) - for obj_id in ids: - res.setdefault(obj_id, 0.0) - for child_id in self.search(cr, uid, - [('parent_id', 'child_of', [obj_id])]): - if child_id != obj_id: - res[obj_id] += res.get(child_id, 0.0) - for id in ids: - res[id] = round(res.get(id, 0.0),2) - return res + + return self._compute_currency_for_level_tree(cr, uid, ids, ids2, res, acc_set, context) def _ca_to_invoice_calc(self, cr, uid, ids, name, arg, context={}): res = {} @@ -59,6 +53,10 @@ class account_analytic_account(osv.osv): ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: # Amount uninvoiced hours to invoice at sale price + # Warning + # This computation doesn't take care of pricelist ! + # Just consider list_price + acc_set = ",".join(map(str, ids2)) cr.execute("""SELECT account_analytic_account.id, \ COALESCE(sum (product_template.list_price * \ account_analytic_line.unit_amount * \ @@ -83,17 +81,6 @@ class account_analytic_account(osv.osv): for account_id, sum in cr.fetchall(): res[account_id] = round(sum,2) - # Expense amount and purchase invoice - #acc_set = ",".join(map(str, ids2)) - #cr.execute ("select account_analytic_line.account_id, sum(amount) \ - # from account_analytic_line \ - # join account_analytic_journal \ - # on account_analytic_line.journal_id = account_analytic_journal.id \ - # where account_analytic_line.account_id IN (%s) \ - # and account_analytic_journal.type = 'purchase' \ - # GROUP BY account_analytic_line.account_id;"%acc_set) - #for account_id, sum in cr.fetchall(): - # res2[account_id] = round(sum,2) for obj_id in ids: res.setdefault(obj_id, 0.0) res2.setdefault(obj_id, 0.0) @@ -160,7 +147,9 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - cr.execute("""select account_analytic_line.account_id,COALESCE(sum(amount),0.0) \ + acc_set = ",".join(map(str, ids2)) + cr.execute("""select account_analytic_line.account_id,COALESCE(sum(amount_currency),0.0) \ + from account_analytic_line \ join account_analytic_journal \ on account_analytic_line.journal_id = account_analytic_journal.id \ @@ -169,20 +158,16 @@ class account_analytic_account(osv.osv): GROUP BY account_analytic_line.account_id""",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = round(sum,2) - for obj_id in ids: - res.setdefault(obj_id, 0.0) - for child_id in self.search(cr, uid, - [('parent_id', 'child_of', [obj_id])]): - if child_id != obj_id: - res[obj_id] += res.get(child_id, 0.0) - for id in ids: - res[id] = round(res.get(id, 0.0),2) - return res - + return self._compute_currency_for_level_tree(cr, uid, ids, ids2, res, acc_set, context) + + # TODO Take care of pricelist and purchase ! def _ca_theorical_calc(self, cr, uid, ids, name, arg, context={}): res = {} res2 = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) + # Warning + # This computation doesn't take care of pricelist ! + # Just consider list_price if ids2: cr.execute("""select account_analytic_line.account_id as account_id, \ COALESCE(sum((account_analytic_line.unit_amount * pt.list_price) \ @@ -205,7 +190,7 @@ class account_analytic_account(osv.osv): GROUP BY account_analytic_line.account_id""",(ids2,)) for account_id, sum in cr.fetchall(): res2[account_id] = round(sum,2) - + for obj_id in ids: res.setdefault(obj_id, 0.0) res2.setdefault(obj_id, 0.0) @@ -214,7 +199,7 @@ class account_analytic_account(osv.osv): if child_id != obj_id: res[obj_id] += res.get(child_id, 0.0) res[obj_id] += res2.get(child_id, 0.0) - + # sum both result on account_id for id in ids: res[id] = round(res.get(id, 0.0),2) + round(res2.get(id, 0.0),2) @@ -289,7 +274,7 @@ class account_analytic_account(osv.osv): def _remaining_hours_calc(self, cr, uid, ids, name, arg, context={}): res = {} for account in self.browse(cr, uid, ids): - if account.quantity_max <> 0: + if account.quantity_max != 0: res[account.id] = account.quantity_max - account.hours_quantity else: res[account.id]=0.0 @@ -323,7 +308,7 @@ class account_analytic_account(osv.osv): for account in self.browse(cr, uid, ids): if account.ca_invoiced == 0: res[account.id]=0.0 - elif account.total_cost <> 0.0: + elif account.total_cost != 0.0: res[account.id] = -(account.real_margin / account.total_cost) * 100 else: res[account.id] = 0.0 @@ -334,7 +319,7 @@ class account_analytic_account(osv.osv): def _remaining_ca_calc(self, cr, uid, ids, name, arg, context={}): res = {} for account in self.browse(cr, uid, ids): - if account.amount_max <> 0: + if account.amount_max != 0: res[account.id] = account.amount_max - account.ca_invoiced else: res[account.id]=0.0 diff --git a/addons/analytic/project.py b/addons/analytic/project.py index 7e0ab40c63a..1f24a99d235 100644 --- a/addons/analytic/project.py +++ b/addons/analytic/project.py @@ -33,65 +33,19 @@ class account_analytic_account(osv.osv): _name = 'account.analytic.account' _description = 'Analytic Accounts' - def _credit_calc(self, cr, uid, ids, name, arg, context={}): - - where_date = '' - if context.get('from_date',False): - where_date += " AND l.date >= '" + context['from_date'] + "'" - if context.get('to_date',False): - where_date += " AND l.date <= '" + context['to_date'] + "'" - - cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount<0 and a.id =ANY(%s) GROUP BY a.id",(ids,)) - r = dict(cr.fetchall()) - for i in ids: - r.setdefault(i,0.0) - return r - - def _debit_calc(self, cr, uid, ids, name, arg, context={}): - - where_date = '' - if context.get('from_date',False): - where_date += " AND l.date >= '" + context['from_date'] + "'" - if context.get('to_date',False): - where_date += " AND l.date <= '" + context['to_date'] + "'" - - cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount>0 and a.id =ANY(%s) GROUP BY a.id" ,(ids,)) - r= dict(cr.fetchall()) - for i in ids: - r.setdefault(i,0.0) - return r - - def _balance_calc(self, cr, uid, ids, name, arg, context={}): - res = {} - ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) - for i in ids: - res.setdefault(i,0.0) - if not ids2: - return res - - where_date = '' - if context.get('from_date',False): - where_date += " AND l.date >= '" + context['from_date'] + "'" - if context.get('to_date',False): - where_date += " AND l.date <= '" + context['to_date'] + "'" - - cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE a.id =ANY(%s) GROUP BY a.id",(ids2,)) - - for account_id, sum in cr.fetchall(): - res[account_id] = sum - - cr.execute("SELECT a.id, r.currency_id FROM account_analytic_account a INNER JOIN res_company r ON (a.company_id = r.id) where a.id =ANY(%s)",(ids2,)) - + def _compute_currency_for_level_tree(self, cr, uid, ids, ids2, res, acc_set, context={}): + # Handle multi-currency on each level of analytic account + # This is a refactoring of _balance_calc computation + cr.execute("SELECT a.id, r.currency_id FROM account_analytic_account a INNER JOIN res_company r ON (a.company_id = r.id) where a.id in (%s)" % acc_set) currency= dict(cr.fetchall()) - res_currency= self.pool.get('res.currency') for id in ids: if id not in ids2: continue for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]): - if child <> id: + if child != id: res.setdefault(id, 0.0) - if currency[child]<>currency[id]: + if currency[child]!=currency[id]: res[id] += res_currency.compute(cr, uid, currency[child], currency[id], res.get(child, 0.0), context=context) else: res[id] += res.get(child, 0.0) @@ -104,24 +58,88 @@ class account_analytic_account(osv.osv): return dict([(i, res[i]) for i in ids ]) - def _quantity_calc(self, cr, uid, ids, name, arg, context={}): - #XXX must convert into one uom + + def _credit_calc(self, cr, uid, ids, name, arg, context={}): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) acc_set = ",".join(map(str, ids2)) - + for i in ids: res.setdefault(i,0.0) - - if not acc_set: + + if not ids2: return res - + where_date = '' if context.get('from_date',False): where_date += " AND l.date >= '" + context['from_date'] + "'" if context.get('to_date',False): where_date += " AND l.date <= '" + context['to_date'] + "'" + cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount_currency<0 and a.id =ANY(%s) GROUP BY a.id",(ids2,)) + r = dict(cr.fetchall()) + return self._compute_currency_for_level_tree(cr, uid, ids, ids2, r, acc_set, context) + + def _debit_calc(self, cr, uid, ids, name, arg, context={}): + res = {} + ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) + acc_set = ",".join(map(str, ids2)) + + for i in ids: + res.setdefault(i,0.0) + + if not ids2: + return res + + where_date = '' + if context.get('from_date',False): + where_date += " AND l.date >= '" + context['from_date'] + "'" + if context.get('to_date',False): + where_date += " AND l.date <= '" + context['to_date'] + "'" + cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount_currency>0 and a.id =ANY(%s) GROUP BY a.id" ,(ids2,)) + r= dict(cr.fetchall()) + return self._compute_currency_for_level_tree(cr, uid, ids, ids2, r, acc_set, context) + + def _balance_calc(self, cr, uid, ids, name, arg, context={}): + res = {} + ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) + acc_set = ",".join(map(str, ids2)) + + for i in ids: + res.setdefault(i,0.0) + + if not ids2: + return res + + where_date = '' + if context.get('from_date',False): + where_date += " AND l.date >= '" + context['from_date'] + "'" + if context.get('to_date',False): + where_date += " AND l.date <= '" + context['to_date'] + "'" + cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE a.id =ANY(%s) GROUP BY a.id",(ids2,)) + + for account_id, sum in cr.fetchall(): + res[account_id] = sum + return self._compute_currency_for_level_tree(cr, uid, ids, ids2, res, acc_set, context) + + def _quantity_calc(self, cr, uid, ids, name, arg, context={}): + #XXX must convert into one uom + res = {} + ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) + acc_set = ",".join(map(str, ids2)) + + for i in ids: + res.setdefault(i,0.0) + + if not ids2: + return res + + where_date = '' + if context.get('from_date',False): + where_date += " AND l.date >= '" + context['from_date'] + "'" + if context.get('to_date',False): + where_date += " AND l.date <= '" + context['to_date'] + "'" + cr.execute('SELECT a.id, COALESCE(SUM(l.unit_amount), 0) \ FROM account_analytic_account a \ LEFT JOIN account_analytic_line l ON (a.id = l.account_id ' + where_date + ') \ @@ -134,7 +152,7 @@ class account_analytic_account(osv.osv): if id not in ids2: continue for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]): - if child <> id: + if child != id: res.setdefault(id, 0.0) res[id] += res.get(child, 0.0) return dict([(i, res[i]) for i in ids]) @@ -161,11 +179,14 @@ class account_analytic_account(osv.osv): result[rec.id] = (rec.company_id.currency_id.id,rec.company_id.currency_id.code) or False return result + def _get_account_currency(self, cr, uid, ids, field_name, arg, context={}): + result=self._get_company_currency(cr, uid, ids, field_name, arg, context={}) + return result + _columns = { 'name' : fields.char('Account Name', size=128, required=True), 'complete_name': fields.function(_complete_name_calc, method=True, type='char', string='Full Account Name'), 'code' : fields.char('Account Code', size=24), -# 'active' : fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the analytic account without removing it."), 'type': fields.selection([('view','View'), ('normal','Normal')], 'Account Type'), 'description' : fields.text('Description'), 'parent_id': fields.many2one('account.analytic.account', 'Parent Analytic Account', select=2), @@ -190,6 +211,7 @@ class account_analytic_account(osv.osv): \n* And finally when all the transactions are over, it can be in \'Close\' state. \ \n* The project can be in either if the states \'Template\' and \'Running\'.\n If it is template then we can make projects based on the template projects. If its in \'Running\' state it is a normal project.\ \n If it is to be reviewed then the state is \'Pending\'.\n When the project is completed the state is set to \'Done\'.'), + 'currency_id': fields.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Account currency', store=True), } def _default_company(self, cr, uid, context={}): @@ -198,14 +220,13 @@ class account_analytic_account(osv.osv): return user.company_id.id return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0] _defaults = { -# 'active' : lambda *a : True, 'type' : lambda *a : 'normal', 'company_id': _default_company, 'state' : lambda *a : 'open', 'user_id' : lambda self,cr,uid,ctx : uid, 'partner_id': lambda self,cr, uid, ctx: ctx.get('partner_id', False), 'contact_id': lambda self,cr, uid, ctx: ctx.get('contact_id', False), - 'date_start': lambda *a: time.strftime('%Y-%m-%d') + 'date_start': lambda *a: time.strftime('%Y-%m-%d') } def check_recursion(self, cr, uid, ids, parent=None): @@ -260,3 +281,4 @@ class account_analytic_account(osv.osv): return self.name_get(cr, uid, account, context=context) account_analytic_account() + diff --git a/addons/analytic_user_function/analytic_user_function.py b/addons/analytic_user_function/analytic_user_function.py index 852d0750a42..c5c2af729a0 100644 --- a/addons/analytic_user_function/analytic_user_function.py +++ b/addons/analytic_user_function/analytic_user_function.py @@ -99,8 +99,11 @@ class hr_analytic_timesheet(osv.osv): _('There is no expense account define ' \ 'for this product: "%s" (id:%d)') % \ (r.product_id.name, r.product_id.id,)) - amount = unit_amount * self.pool.get('product.uom')._compute_price(cr, uid, - r.product_id.uom_id.id, r.product_id.standard_price, False) + # Compute based on pricetype + amount_unit=self.on_change_unit_amount(cr, uid, ids, + r.product_id.id, unit_amount, r.product_id.uom_id.id)['value']['amount'] + + amount = unit_amount * amount_unit res ['value']['amount']= - round(amount, 2) res ['value']['general_account_id']= a return res @@ -132,8 +135,11 @@ class hr_analytic_timesheet(osv.osv): _('There is no expense account define ' \ 'for this product: "%s" (id:%d)') % \ (r.product_id.name, r.product_id.id,)) - amount = unit_amount * r.product_id.uom_id._compute_price(cr, uid, - r.product_id.uom_id.id, r.product_id.standard_price, False) + # Compute based on pricetype + amount_unit=self.on_change_unit_amount(cr, uid, ids, + r.product_id.id, unit_amount, r.product_id.uom_id.id)['value']['amount'] + + amount = unit_amount * amount_unit res ['value']['amount']= - round(amount, 2) res ['value']['general_account_id']= a return res diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index 6c31e6c3b69..5e71e4614df 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -210,12 +210,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 580a0d371a5..3743b557a08 100644 --- a/addons/hr_expense/hr_expense_view.xml +++ b/addons/hr_expense/hr_expense_view.xml @@ -73,8 +73,8 @@
- - + + diff --git a/addons/hr_timesheet/hr_timesheet.py b/addons/hr_timesheet/hr_timesheet.py index 9358cd085e9..d3dc6005082 100644 --- a/addons/hr_timesheet/hr_timesheet.py +++ b/addons/hr_timesheet/hr_timesheet.py @@ -57,7 +57,9 @@ class hr_analytic_timesheet(osv.osv): res = {} # if prod_id and unit_amount: if prod_id: - res = self.pool.get('account.analytic.line').on_change_unit_amount(cr, uid, id, prod_id, unit_amount,unit, context) + # 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,unit, context) return res def _getEmployeeProduct(self, cr, uid, context): diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py index 41e65e2d8fc..4b8fad8fab5 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py @@ -52,6 +52,7 @@ class account_analytic_account(osv.osv): res[id] = round(res.get(id, 0.0),2) return res + _inherit = "account.analytic.account" _columns = { 'pricelist_id' : fields.many2one('product.pricelist', 'Sale Pricelist'), @@ -77,7 +78,6 @@ class account_analytic_line(osv.osv): } def unlink(self, cursor, user, ids, context=None): - self._check(cursor, user, ids) return super(account_analytic_line,self).unlink(cursor, user, ids, context=context) @@ -90,11 +90,11 @@ class account_analytic_line(osv.osv): select = ids if isinstance(select, (int, long)): select = [ids] - if ( not vals.has_key('invoice_id')) or vals['invoice_id' ] == False: - for line in self.browse(cr, uid, select): - if line.invoice_id: - raise osv.except_osv(_('Error !'), - _('You can not modify an invoiced analytic line!')) + if ( not vals.has_key('invoice_id')) or vals['invoice_id' ] == False: + for line in self.browse(cr, uid, select): + if line.invoice_id: + raise osv.except_osv(_('Error !'), + _('You can not modify an invoiced analytic line!')) return True def copy(self, cursor, user, obj_id, default=None, context=None): diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice_view.xml b/addons/hr_timesheet_invoice/hr_timesheet_invoice_view.xml index 9f0a16ae428..1e432fea9e1 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice_view.xml +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice_view.xml @@ -20,7 +20,19 @@ - + + + account.analytic.account.form + account.analytic.account + + form + + + + + + + hr.analytic.timesheet.form hr.analytic.timesheet diff --git a/addons/multi_company/__init__.py b/addons/multi_company/__init__.py index 2aefd8b3c11..4716d0d109b 100644 --- a/addons/multi_company/__init__.py +++ b/addons/multi_company/__init__.py @@ -18,6 +18,5 @@ # along with this program. If not, see . # ############################################################################## - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/multi_company/__terp__.py b/addons/multi_company/__terp__.py index df892aca33c..b3126b9bf99 100644 --- a/addons/multi_company/__terp__.py +++ b/addons/multi_company/__terp__.py @@ -32,7 +32,7 @@ 'depends': [ 'base', 'sale', - 'project' + 'project', ], 'init_xml': [], 'update_xml': [ diff --git a/addons/product/__init__.py b/addons/product/__init__.py index e5f930e8c2f..3052a02d212 100644 --- a/addons/product/__init__.py +++ b/addons/product/__init__.py @@ -23,6 +23,6 @@ import pricelist import report import partner import wizard - +import company # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/product/__terp__.py b/addons/product/__terp__.py index 7b508d7440f..8c0a8340984 100644 --- a/addons/product/__terp__.py +++ b/addons/product/__terp__.py @@ -54,6 +54,7 @@ 'product_view.xml', 'pricelist_view.xml', 'partner_view.xml', + 'company_view.xml', 'product_wizard.xml', 'process/product_process.xml' ], diff --git a/addons/product/company.py b/addons/product/company.py new file mode 100644 index 00000000000..f23d010b600 --- /dev/null +++ b/addons/product/company.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from osv import fields, osv + + +class res_company(osv.osv): + _inherit = 'res.company' + _columns = { + 'property_valuation_price_type': fields.property( + 'product.price.type', + type='many2one', + relation='product.price.type', + domain=[], + string="Valuation Price Type", + method=True, + view_load=True, + help="The price type field in the selected price type will be used, instead of the default one, \ + for valuation of product in the current company"), + } + + def _check_currency(self, cr, uid, ids): + for rec in self.browse(cr, uid, ids): + if rec.currency_id.id <> rec.property_valuation_price_type.currency_id.id: + return False + return True + + _constraints = [ + (_check_currency, 'Error! You can not chooes a pricetype in a different currency than your company (Not supported now).', ['property_valuation_price_type']) + ] + +res_company() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/product/company_view.xml b/addons/product/company_view.xml new file mode 100644 index 00000000000..eb0294e2daa --- /dev/null +++ b/addons/product/company_view.xml @@ -0,0 +1,18 @@ + + + + + + res.company.product.property.form.inherit + res.company + form + + + + + + + + + + diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 7e7fcd17790..b0b867ac547 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -62,6 +62,7 @@ class price_type(osv.osv): "active": lambda *args: True, "currency_id": _get_currency } + price_type() #---------------------------------------------------------- diff --git a/addons/product/product_data.xml b/addons/product/product_data.xml index 2f000fdbfc6..8037453101e 100644 --- a/addons/product/product_data.xml +++ b/addons/product/product_data.xml @@ -73,7 +73,6 @@ parameter) will see those record just disappear. - @@ -81,6 +80,7 @@ parameter) will see those record just disappear. Sale Pricelist sale +