diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py
index 3e3266044b4..7b0723ca07f 100644
--- a/addons/account/account_analytic_line.py
+++ b/addons/account/account_analytic_line.py
@@ -24,10 +24,38 @@ import time
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
+ result[rec.id] = 0.0
+ 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)
+ return result
+
+ def _get_account_currency(self, cr, uid, ids, field_name, arg, context={}):
+ result = {}
+ for rec in self.browse(cr, uid, ids, context):
+ if rec.company_id.currency_id.id <> rec.account_id.currency_id.id:
+ result[rec.id] = (rec.account_id.currency_id.id,rec.account_id.currency_id.code)
+ else:
+ result[rec.id] = False
+ return result
+
_columns = {
'name' : fields.char('Description', size=256, required=True),
'date' : fields.date('Date', required=True),
@@ -42,13 +70,21 @@ class account_analytic_line(osv.osv):
'code' : fields.char('Code', size=8),
'user_id' : fields.many2one('res.users', 'User',),
'ref': fields.char('Ref.', size=32),
+ 'currency_id': fields.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Currency',
+ store=True, 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=True,
+ help="The amount expressed in the related account currency if not equal to the company one.",
+ ),
+
}
_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 = {}
@@ -72,8 +108,10 @@ 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,
- unit=False, context=None):
+ # Compute the cost based on the valuation pricelist define into company
+ # property_product_pricelist property
+ def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount,company_id,
+ date,unit=False, context=None):
uom_obj = self.pool.get('product.uom')
product_obj = self.pool.get('product.product')
# if unit_amount and prod_id:
@@ -87,8 +125,17 @@ 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 company_id:
+ company_obj = self.pool.get('res.company')
+ else:
+ company_id=self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context)
+ pricelist_id=company_obj.browse(cr,uid,company_id).property_valuation_pricelist.id
+ amount_unit = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist_id],
+ prod_id, unit_amount or 1.0, None, {
+ 'uom': unit,
+ 'date': date,
+ })[pricelist_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 51431ee1be1..d6d68eee76f 100644
--- a/addons/account/project/project.py
+++ b/addons/account/project/project.py
@@ -167,6 +167,10 @@ 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=64, required=True),
'complete_name': fields.function(_complete_name_calc, method=True, type='char', string='Full Account Name'),
@@ -194,6 +198,7 @@ class account_analytic_account(osv.osv):
\n* If any associated partner is there, it can be in \'Open\' state.\
\n* If any pending balance is there it can be in \'Pending\'. \
\n* And finally when all the transactions are over, it can be in \'Close\' state.'),
+ '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={}):
diff --git a/addons/account/project/project_view.xml b/addons/account/project/project_view.xml
index accbbf52d53..ef4da006e49 100644
--- a/addons/account/project/project_view.xml
+++ b/addons/account/project/project_view.xml
@@ -50,6 +50,7 @@
+
@@ -134,6 +135,9 @@
+
+
+
@@ -146,16 +150,19 @@
tree
-
+
-
-
+
+
-
+
+
+
+
@@ -212,13 +219,16 @@
diff --git a/addons/hr_timesheet/hr_timesheet.py b/addons/hr_timesheet/hr_timesheet.py
index 652814b6e02..278b1d0357c 100644
--- a/addons/hr_timesheet/hr_timesheet.py
+++ b/addons/hr_timesheet/hr_timesheet.py
@@ -53,11 +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, unit, context={}):
+ def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount, date, unit, context={}):
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)
+ 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)
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 49ba1d602ad..ab07c4d1633 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_invoice/hr_timesheet_invoice.py b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py
index 182d8843b8c..3236807c928 100644
--- a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py
+++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py
@@ -52,8 +52,15 @@ class account_analytic_account(osv.osv):
res[id] = round(res.get(id, 0.0),2)
return res
+ def _get_account_currency(self, cr, uid, ids, field_name, arg, context={}):
+ result=super(account_analytic_account, self)._get_account_currency(cr, uid, ids, field_name, arg, context)
+ for rec in self.browse(cr, uid, ids, context):
+ result[rec.id] = rec.pricelist_id and (rec.pricelist_id.currency_id.id,rec.pricelist_id.currency_id.code) or result[rec.id]
+ return result
+
_inherit = "account.analytic.account"
_columns = {
+ 'currency_id': fields.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Account currency', store=True),
'pricelist_id' : fields.many2one('product.pricelist', 'Sale Pricelist'),
'amount_max': fields.float('Max. Invoice Price'),
'amount_invoiced': fields.function(_invoiced_calc, method=True, string='Invoiced Amount',
@@ -77,7 +84,7 @@ class account_analytic_line(osv.osv):
}
def unlink(self, cursor, user, ids, context=None):
- self._check(cursor, user, ids)
+ # self._check(cursor, user, ids)
return super(account_analytic_line,self).unlink(cursor, user, ids,
context=context)
@@ -90,11 +97,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 4ff5ac27c95..3ca932f6bcd 100644
--- a/addons/hr_timesheet_invoice/hr_timesheet_invoice_view.xml
+++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice_view.xml
@@ -21,7 +21,19 @@
-
+
+
+ account.analytic.account.form
+ account.analytic.account
+
+ form
+
+
+
+
+
+
+
hr.analytic.timesheet.form
hr.analytic.timesheet
diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml b/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml
index be40d8bacef..5452ccf790b 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/product/__init__.py b/addons/product/__init__.py
index 3f95fcb1900..da66b46efec 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 3069a901577..183973a2275 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..32c4f3bccd2
--- /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_pricelist': fields.property(
+ 'product.pricelist',
+ type='many2one',
+ relation='product.pricelist',
+ domain=[('type','=','valuation')],
+ string="Valuation Pricelist",
+ method=True,
+ view_load=True,
+ help="This pricelist will be used, instead of the default one, \
+ for valuation to 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_pricelist.currency_id.id:
+ return False
+ return True
+
+ _constraints = [
+ (_check_currency, 'Error! You can not chooes a pricelist in a different currency than your company.', ['property_valuation_pricelist'])
+ ]
+
+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..5ccd5982de4
--- /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/product_data.xml b/addons/product/product_data.xml
index 2f000fdbfc6..452253f0c96 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,11 @@ parameter) will see those record just disappear.
Sale Pricelist
sale
+
+
+ Valuation Pricelist
+ valuation
+
@@ -107,5 +126,12 @@ parameter) will see those record just disappear.
+
+
+ property_valuation_pricelist
+
+
+
+