[ADD] Field company_id on account.analytic.line
[ADD] Function Field currency_id, amount_currency on account.analytic.line, 
on account.analytic.account currency_id
[ADD] Function field currency_id on account.analytic.account = company currency
[API] Change the on_change_unit_amount signature, adding date and company_id
[IMP] Change the on_change_unit_amount funtcion to base cost price on valuation
 instead of standard price.

Product:
[ADD] Add a new property called property_valuation_pricelist into res.company.
purpose of this pricelist is to compute the cost price for a given 
y.

Hr_timesheet:
[API] Change the on_change_unit_amount signature, adding date

Hr_timesheet_invoice
[IMP] Function field currency_id of account.analytic.account base computation
  pricelist currency instead of company currency  

Hr_timesheet_sheet:
[IMP] Add support of new signature for on_change_unit_amount

bzr revid: joel.grandguillaume@camptocamp.com-20091217141332-23u4v79m3pbst7u9
This commit is contained in:
Joel Grand-Guillaume 2009-12-17 15:13:32 +01:00
parent df11433d89
commit ff19c0f96b
13 changed files with 216 additions and 35 deletions

View File

@ -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,

View File

@ -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={}):

View File

@ -50,6 +50,7 @@
<field name="parent_id" on_change="on_change_parent(parent_id)"/>
<field name="company_id" select="2" widget="selection"/>
<field name="type" select="2"/>
<field name="company_currency_id" select="2"/>
</group>
<notebook colspan="4">
<page string="Account Data">
@ -134,6 +135,9 @@
<field name="move_id" select="2"/>
<field name="unit_amount" select="2"/>
<field name="ref" select="2"/>
<field name="currency_id" select="2"/>
<field name="amount_currency" select="2"/>
<field name="company_id" select="2"/>
<newline/>
<field name="product_id" select="2"/>
<field name="product_uom_id" select="2"/>
@ -146,16 +150,19 @@
<field name="type">tree</field>
<field name="arch" type="xml">
<tree editable="top" string="Analytic Entries">
<field name="date"/>
<field name="date" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)"/>
<field name="name"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)" sum="Total quantity"/>
<field name="product_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
<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 domain="[('type','=','normal')]" name="account_id"/>
<field invisible="True" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_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 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)"/>
</tree>
</field>
</record>
@ -212,13 +219,16 @@
<form string="Project line">
<field name="name"/>
<field name="account_id"/>
<field name="date"/>
<field name="date" on_change="on_change_unit_amount(product_id, unit_amount, company_id,date, product_uom_id)"/>
<field name="journal_id"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
<field name="product_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_id)"/>
<field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, product_uom_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 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)"/>
</form>
</field>
</record>

View File

@ -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):

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, 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="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="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, product_uom_id)"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, date, product_uom_id)"/>
<newline/>
<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="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 domain="[('type','=','normal'),('state', '&lt;&gt;', 'close')]" name="account_id" select="1"/>
<field name="amount" select="2"/>

View File

@ -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):

View File

@ -21,7 +21,19 @@
</field>
</field>
</record>
<record id="view_account_analytic_account_form" model="ir.ui.view">
<field name="name">account.analytic.account.form</field>
<field name="model">account.analytic.account</field>
<field name="inherit_id" ref="account.view_account_analytic_account_form"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="company_currency_id" select="2" position="replace">
<field name="currency_id" select="2"/>
</field>
</field>
</record>
<record id="hr_timesheet_line_form" model="ir.ui.view">
<field name="name">hr.analytic.timesheet.form</field>
<field name="model">hr.analytic.timesheet</field>

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, product_uom_id)" widget="float_time"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, date, 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, product_uom_id)"/>
<field invisible="1" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, date, 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, product_uom_id)" widget="float_time"/>
<field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, date, 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, product_uom_id)"/>
<field invisible="1" name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, date, product_uom_id)"/>
<field name="amount"/>
<field name="general_account_id"/>
<field name="user_id" required="1"/>

View File

@ -23,6 +23,6 @@ import pricelist
import report
import partner
import wizard
import company
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -54,6 +54,7 @@
'product_view.xml',
'pricelist_view.xml',
'partner_view.xml',
'company_view.xml',
'product_wizard.xml',
'process/product_process.xml'
],

53
addons/product/company.py Normal file
View File

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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:

View File

@ -0,0 +1,18 @@
<openerp>
<data>
<record id="view_company_property_form" model="ir.ui.view">
<field name="name">res.company.product.property.form.inherit</field>
<field name="model">res.company</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_company_form"/>
<field name="arch" type="xml">
<field name="currency_id" position="after">
<field name="property_valuation_pricelist"/>
</field>
</field>
</record>
</data>
</openerp>

View File

@ -73,7 +73,6 @@ parameter) will see those record just disappear.
<!--
Price list type
-->
@ -81,6 +80,11 @@ parameter) will see those record just disappear.
<field name="name">Sale Pricelist</field>
<field name="key">sale</field>
</record>
<record id="pricelist_type_valuation" model="product.pricelist.type">
<field name="name">Valuation Pricelist</field>
<field name="key">valuation</field>
</record>
<!--
Price list
@ -99,6 +103,21 @@ parameter) will see those record just disappear.
<field name="name">Default Public Pricelist Line</field>
</record>
<record id="list_v" model="product.pricelist">
<field name="name">Valuation Pricelist</field>
<field name="type">valuation</field>
</record>
<record id="ver_v" model="product.pricelist.version">
<field name="pricelist_id" ref="list_v"/>
<field name="name">Default Valuation Pricelist Version</field>
</record>
<record id="item_v" model="product.pricelist.item">
<field name="price_version_id" ref="ver_v"/>
<field name="base" ref="standard_price"/>
<field name="name">Default Valuation Pricelist Line</field>
</record>
<!--
Property
-->
@ -107,5 +126,12 @@ parameter) will see those record just disappear.
<field name="fields_id" search="[('model','=','res.partner'),('name','=','property_product_pricelist')]"/>
<field eval="'product.pricelist,'+str(ref('list0'))" name="value"/>
</record>
<record forcecreate="True" id="property_valuation_pricelist" model="ir.property">
<field name="name">property_valuation_pricelist</field>
<field name="fields_id" search="[('model','=','res.company'),('name','=','property_valuation_pricelist')]"/>
<field eval="'product.pricelist,'+str(ref('list_v'))" name="value"/>
</record>
</data>
</openerp>