[IMP] Change pricelist for price type into company property

[IMP] Change all valuation according to price type instead of pricelist
[IMP] Compute the aveerage price based on the define price type in the company, this allow company to have different cost price

bzr revid: joel.grandguillaume@camptocamp.com-20091223152806-cacd3e8loi7tea53
This commit is contained in:
Joel Grand-Guillaume 2009-12-23 16:28:06 +01:00
parent 4a628b63d7
commit ffd766bd42
11 changed files with 50 additions and 74 deletions

View File

@ -83,7 +83,6 @@ class account_analytic_line(osv.osv):
'account.analytic.account': (_get_account_line, ['company_id'], 50),
'account.analytic.line': (lambda self,cr,uid,ids,c={}: ids, ['amount','unit_amount'],10),
},
# multi='all',
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',
@ -91,7 +90,6 @@ class account_analytic_line(osv.osv):
'account.analytic.account': (_get_account_line, ['company_id'], 50),
'account.analytic.line': (lambda self,cr,uid,ids,c={}: ids, ['amount','unit_amount'],10),
},
# multi='all',
help="The amount expressed in the related account currency if not equal to the company one."),
'ref': fields.char('Reference', size=32),
}
@ -124,13 +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'])
]
# Compute the cost based on the valuation pricelist define into company
# property_product_pricelist property
# 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):
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
@ -141,16 +141,13 @@ class account_analytic_line(osv.osv):
_('There is no expense account defined ' \
'for this product: "%s" (id:%d)') % \
(prod.name, prod.id,))
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]
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),

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, res['product_uom_id'])['value']
up = timesheet_obj.on_change_unit_amount(cr, uid, False, res['product_id'], hour, data['form']['date'], res['product_uom_id'])['value']
res['name'] = data['form']['info']
res['account_id'] = data['form']['account_id']
res['unit_amount'] = hour

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import product
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -32,10 +32,12 @@
'depends': [
'base',
'sale',
'project'
'project',
'product',
],
'init_xml': [],
'update_xml': [
"multi_company_view.xml",
#'security/ir.model.access.csv',
],
'demo_xml': [

View File

@ -3,21 +3,13 @@
<data noupdate="1">
<!-- Valuation pricelist -->
<record id="list_usd" model="product.pricelist">
<field name="name">Valuation Pricelist USD</field>
<field name="type">valuation</field>
<!-- Valuation price type -->
<record id="standard_price_usd" model="product.price.type">
<field name="name">Cost Price USD</field>
<field name="field">standard_price_usd</field>
<field name="currency_id" search="[('code','=','USD')]"/>
</record>
<record id="ver_usd" model="product.pricelist.version">
<field name="pricelist_id" ref="list_usd"/>
<field name="name">Default Valuation Pricelist Version USD</field>
</record>
<record id="item_usd" model="product.pricelist.item">
<field name="price_version_id" ref="ver_usd"/>
<field name="base" ref="product.standard_price"/>
<field name="name">Default Valuation Pricelist Line USD</field>
</record>
<!-- Partner -->
<record id="base.main_partner" model="res.partner">
@ -54,7 +46,7 @@
<field name="parent_id" ref="res_company_oerp_editor"/>
<field name="name">OpenERP US</field>
<field name="currency_id" search="[('code','=','USD')]"/>
<field name="property_valuation_pricelist" ref="list_usd"/>
<field name="property_valuation_price_type" ref="standard_price_usd"/>
</record>
<record id="res_company_oerp_be" model="res.company">
<field name="partner_id" ref="res_partner_oerp_be"/>

View File

@ -25,26 +25,26 @@ from osv import fields, osv
class res_company(osv.osv):
_inherit = 'res.company'
_columns = {
'property_valuation_pricelist': fields.property(
'product.pricelist',
'property_valuation_price_type': fields.property(
'product.price.type',
type='many2one',
relation='product.pricelist',
domain=[('type','=','valuation')],
string="Valuation Pricelist",
relation='product.price.type',
domain=[],
string="Valuation Price Type",
method=True,
view_load=True,
help="This pricelist will be used, instead of the default one, \
for valuation to the current company"),
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_pricelist.currency_id.id:
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 pricelist in a different currency than your company.', ['property_valuation_pricelist'])
(_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()

View File

@ -9,7 +9,7 @@
<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 name="property_valuation_price_type"/>
</field>
</field>
</record>

View File

@ -62,6 +62,7 @@ class price_type(osv.osv):
"active": lambda *args: True,
"currency_id": _get_currency
}
price_type()
#----------------------------------------------------------

View File

@ -81,10 +81,6 @@ parameter) will see those record just disappear.
<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
@ -103,21 +99,6 @@ 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
-->
@ -127,10 +108,10 @@ parameter) will see those record just disappear.
<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 forcecreate="True" id="property_valuation_price_type" model="ir.property">
<field name="name">property_valuation_price_type</field>
<field name="fields_id" search="[('model','=','res.company'),('name','=','property_valuation_price_type')]"/>
<field eval="'product.price.type,'+str(ref('standard_price'))" name="value"/>
</record>
</data>

View File

@ -1328,14 +1328,13 @@ class stock_move(osv.osv):
q = product_uom_obj._compute_qty(cr, uid, move.product_uom.id, move.product_qty, default_uom)
if move.product_id.cost_method == 'average' and move.price_unit:
amount = q * move.price_unit
# Base computation on valuation pricelist
# Base computation on valuation price type
else:
company_id=move.company_id.id
pricelist_id = self.pool.get('res.company').browse(cr,uid,company_id).property_valuation_pricelist.id
amount_unit = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist_id],
move.product_id.id, q or 1.0, None, {
'date': date,
})[pricelist_id]
pricetype=self.pool.get('product.price.type').browse(cr,uid,move.company_id.property_valuation_price_type.id)
amount_unit=move.product_id.price_get(cr, uid, ids, pricetype.field, context)
amount=amount_unit * q or 1.0
# amount = q * move.product_id.standard_price

View File

@ -131,7 +131,7 @@ 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)
@ -140,11 +140,14 @@ 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 = ((amount_unit * product.qty_available)\
+ (new_price * qty))/(product.qty_available + qty)
# Write the field according to price type field
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: