rate = float(tot2)/float(tot1)
return rate
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
access_account_fiscalyear_employee,account.fiscalyear employee,model_account_fiscalyear,base.group_user,1,0,0,0
access_res_currency_account_manager,res.currency account manager,base.model_res_currency,group_account_manager,1,1,1,1
access_res_currency_rate_account_manager,res.currency.rate account manager,base.model_res_currency_rate,group_account_manager,1,1,1,1
-access_res_currency_rate_type_account_manager,res.currency.rate.type account manager,base.model_res_currency_rate_type,group_account_manager,1,1,1,1
access_account_invoice_user,account.invoice user,model_account_invoice,base.group_user,1,0,0,0
access_account_invoice_user,account.invoice.line user,model_account_invoice_line,base.group_user,1,0,0,0
access_account_payment_term_partner_manager,account.payment.term partner manager,model_account_payment_term,base.group_user,1,0,0,0
res.append((field.name, field.field_description))
return res
+ def _get_field_currency(self, cr, uid, fname, ctx):
+ ids = self.search(cr, uid, [('field','=',fname)], context=ctx)
+ return self.browse(cr, uid, ids, context=ctx)[0].currency_id
+
def _get_currency(self, cr, uid, ctx):
comp = self.pool.get('res.users').browse(cr,uid,uid).company_id
if not comp:
keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list)
if not context.get('pricelist'):
- context['pricelist'] = int(self.get_pricelist())
+ pricelist = self.get_pricelist()
+ context['pricelist'] = int(pricelist)
+ else:
+ pricelist = pool.get('product.pricelist').browse(cr, uid, context['pricelist'], context)
+
product_obj = pool.get('product.template')
product_count = product_obj.search_count(cr, uid, domain, context=context)
categs = filter(lambda x: not x.parent_id, categories)
attributes_obj = request.registry['product.attribute']
- attributes_ids = attributes_obj.search(cr, uid, [], context=request.context)
- attributes = attributes_obj.browse(cr, uid, attributes_ids, context=request.context)
+ attributes_ids = attributes_obj.search(cr, uid, [], context=context)
+ attributes = attributes_obj.browse(cr, uid, attributes_ids, context=context)
+
+ from_currency = pool.get('product.price.type')._get_field_currency(cr, uid, 'list_price', context)
+ to_currency = pricelist.currency_id
+ compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context)
values = {
'search': search,
'attrib_values': attrib_values,
'attrib_set': attrib_set,
'pager': pager,
- 'pricelist': self.get_pricelist(),
+ 'pricelist': pricelist,
'products': products,
'bins': table_compute().process(products),
'rows': PPR,
'styles': styles,
'categories': categs,
'attributes': attributes,
+ 'compute_currency': compute_currency,
'keep': keep,
'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids],
'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib',i) for i in attribs]),
}
-
return request.website.render("website_sale.products", values)
@http.route(['/shop/product/<model("product.template"):product>'], type='http', auth="public", website=True)
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
order = request.website.sale_get_order()
+ from_currency = pool.get('product.price.type')._get_field_currency(cr, uid, 'list_price', context)
+ to_currency = order.pricelist_id.currency_id
+ compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context)
+
values = {
'order': order,
+ 'compute_currency': compute_currency,
'suggested_products': [],
}
if order:
_columns = {
'pricelist_id': fields.related('user_id','partner_id','property_product_pricelist',
- type='many2one', relation='product.pricelist', string='Default pricelist'),
+ type='many2one', relation='product.pricelist', string='Default Pricelist'),
'currency_id': fields.related('pricelist_id','currency_id',
- type='many2one', relation='res.currency', string='Default pricelist'),
+ type='many2one', relation='res.currency', string='Default Currency'),
}
def sale_product_domain(self, cr, uid, ids, context=None):
'sale_order_code_pricelist_id': False,
})
- def compute_curency(self, cr, uid, ids, from_amount, from_currency_id=None, context=None):
- from_currency_id = from_currency_id or self.browse(cr, SUPERUSER_ID, ids[0]).currency_id.id
- to_currency_id = self.pool.get("res.users").browse(cr, uid, uid).partner_id.property_product_pricelist.currency_id.id
- return self.pool['res.currency'].compute(cr, uid, from_currency_id, to_currency_id, from_amount, context=context)
-# vim:et:
<h5><strong><a itemprop="name" t-att-href="keep('/shop/product/%s' % slug(product), page=(pager['page']['num'] if pager['page']['num']>1 else None))" t-field="product.name"/></strong></h5>
<div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price" t-if="product.product_variant_ids">
<b>
- <t t-if="(website.compute_curency(product.lst_price) - product.price) > 0.1">
+ <t t-if="(compute_currency(product.lst_price) - product.price) > 0.1">
<del class="text-danger" style="white-space: nowrap;" t-field="product.lst_price" t-field-options='{
"widget": "monetary",
"from_currency": "website.currency_id",
<template id="product_price">
<div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price mt16">
<h4 class="oe_price_h4 css_editable_mode_hidden">
- <span class="text-danger oe_default_price" t-att-style="'' if (website.compute_curency(product.lst_price) - product.price) > 0.1 else 'display: none;'" style="text-decoration: line-through; white-space: nowrap;"
+ <span class="text-danger oe_default_price" t-att-style="'' if (compute_currency(product.lst_price) - product.price) > 0.1 else 'display: none;'" style="text-decoration: line-through; white-space: nowrap;"
t-field="product.lst_price"
t-field-options='{
"widget": "monetary",
<div class="text-muted" t-field="line.name"/>
</td>
<td class="text-center" name="price">
- <t t-if="(website.compute_curency(line.product_id.lst_price) - line.price_unit) > 0.1">
+ <t t-if="(compute_currency(line.product_id.lst_price) - line.price_unit) > 0.01">
<del class="text-danger" style="white-space: nowrap;"
t-field="line.product_id.lst_price" t-field-options='{
"widget": "monetary",
<div class="text-muted" t-field="product.description_sale"/>
</td>
<td>
- <t t-if="(website.compute_curency(product.lst_price) - product.price) > 0.1">
+ <t t-if="(compute_currency(product.lst_price) - product.price) > 0.1">
<del class="text-danger" style="white-space: nowrap;"
t-field="product.lst_price" t-field-options='{
"widget": "monetary",
</div>
</td>
<td>
- <span t-attf-class="text-danger oe_default_price" t-att-style="'' if (website.compute_curency(product.lst_price) - product.price) > 0.1 else 'display: none;'" style="text-decoration: line-through; white-space: nowrap;"
+ <span t-attf-class="text-danger oe_default_price" t-att-style="'' if (compute_currency(product.lst_price) - product.price) > 0.1 else 'display: none;'" style="text-decoration: line-through; white-space: nowrap;"
t-field="product.lst_price"
t-field-options='{
"widget": "monetary",
</div>
</td>
<td>
- <t t-if="(website.compute_curency(product.lst_price) - product.price) > 0.1">
+ <t t-if="(compute_currency(product.lst_price) - product.price) > 0.1">
<span class="text-danger" style="text-decoration: line-through; white-space: nowrap;"
t-field="product.lst_price"
t-field-options='{
res = {}
date = context.get('date') or time.strftime('%Y-%m-%d')
- # Convert False values to None ...
- currency_rate_type = context.get('currency_rate_type_id') or None
- # ... and use 'is NULL' instead of '= some-id'.
- operator = '=' if currency_rate_type else 'is'
for id in ids:
cr.execute('SELECT rate FROM res_currency_rate '
'WHERE currency_id = %s '
'AND name <= %s '
- 'AND currency_rate_type_id ' + operator + ' %s '
'ORDER BY name desc LIMIT 1',
- (id, date, currency_rate_type))
+ (id, date))
if cr.rowcount:
res[id] = cr.fetchone()[0]
elif not raise_on_no_rate:
if context is None:
context = {}
ctx = context.copy()
- ctx.update({'currency_rate_type_id': ctx.get('currency_rate_type_from')})
from_currency = self.browse(cr, uid, from_currency.id, context=ctx)
-
- ctx.update({'currency_rate_type_id': ctx.get('currency_rate_type_to')})
to_currency = self.browse(cr, uid, to_currency.id, context=ctx)
if from_currency.rate == 0 or to_currency.rate == 0:
'at the date: %s') % (currency_symbol, date))
return to_currency.rate/from_currency.rate
- def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount,
- round=True, currency_rate_type_from=False, currency_rate_type_to=False, context=None):
- if not context:
- context = {}
- if not from_currency_id:
- from_currency_id = to_currency_id
- if not to_currency_id:
- to_currency_id = from_currency_id
- xc = self.browse(cr, uid, [from_currency_id,to_currency_id], context=context)
- from_currency = (xc[0].id == from_currency_id and xc[0]) or xc[1]
- to_currency = (xc[0].id == to_currency_id and xc[0]) or xc[1]
- if (to_currency_id == from_currency_id) and (currency_rate_type_from == currency_rate_type_to):
+ def _compute(self, cr, uid, from_currency, to_currency, from_amount, round=True, context=None):
+ if (to_currency.id == from_currency.id):
if round:
return self.round(cr, uid, to_currency, from_amount)
else:
return from_amount
else:
- context.update({'currency_rate_type_from': currency_rate_type_from, 'currency_rate_type_to': currency_rate_type_to})
rate = self._get_conversion_rate(cr, uid, from_currency, to_currency, context=context)
if round:
return self.round(cr, uid, to_currency, from_amount * rate)
else:
return from_amount * rate
-class res_currency_rate_type(osv.osv):
- _name = "res.currency.rate.type"
- _description = "Currency Rate Type"
- _columns = {
- 'name': fields.char('Name', required=True, translate=True),
- }
+ def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount,
+ round=True, context=None):
+ context = context or {}
+ if not from_currency_id:
+ from_currency_id = to_currency_id
+ if not to_currency_id:
+ to_currency_id = from_currency_id
+ xc = self.browse(cr, uid, [from_currency_id,to_currency_id], context=context)
+ from_currency = (xc[0].id == from_currency_id and xc[0]) or xc[1]
+ to_currency = (xc[0].id == to_currency_id and xc[0]) or xc[1]
+ return self._compute(cr, uid, from_currency, to_currency, from_amount, round, context)
class res_currency_rate(osv.osv):
_name = "res.currency.rate"
'name': fields.datetime('Date', required=True, select=True),
'rate': fields.float('Rate', digits=(12, 6), help='The rate of the currency to the currency of rate 1'),
'currency_id': fields.many2one('res.currency', 'Currency', readonly=True),
- 'currency_rate_type_id': fields.many2one('res.currency.rate.type', 'Currency Rate Type', help="Allow you to define your own currency rate types, like 'Average' or 'Year to Date'. Leave empty if you simply want to use the normal 'spot' rate type"),
}
_defaults = {
'name': lambda *a: time.strftime('%Y-%m-%d'),
<menuitem action="action_currency_form" id="menu_action_currency_form" parent="menu_localisation" sequence="3" groups="base.group_multi_currency"/>
- <!--
- Currency Rate Type
- -->
- <record id="view_currency_rate_type_form" model="ir.ui.view">
- <field name="name">res.currency.rate.type.form</field>
- <field name="model">res.currency.rate.type</field>
- <field name="arch" type="xml">
- <form string="Currency Rate Type">
- <group>
- <field name="name"/>
- </group>
- </form>
- </field>
- </record>
-
- <record id="action_currency_rate_type_form" model="ir.actions.act_window">
- <field name="name">Currency Rate Type</field>
- <field name="res_model">res.currency.rate.type</field>
- <field name="view_type">form</field>
- <field name="view_mode">tree,form</field>
- </record>
-
- <record id="view_currency_rate_type_search" model="ir.ui.view">
- <field name="name">res.currency.rate.type.search</field>
- <field name="model">res.currency.rate.type</field>
- <field name="arch" type="xml">
- <search string="Currency Rate Type">
- <field name="name" string="Name"/>
- </search>
- </field>
- </record>
-
-
</data>
</openerp>
"access_res_country_group_group_user","res_country_group group_user","model_res_country_group","group_partner_manager",1,1,1,1
"access_res_currency_group_all","res_currency group_all","model_res_currency",,1,0,0,0
"access_res_currency_rate_group_all","res_currency_rate group_all","model_res_currency_rate",,1,0,0,0
-"access_res_currency_rate_type_group_all","res_currency_rate_type group_all","model_res_currency_rate_type",,1,0,0,0
"access_res_currency_group_system","res_currency group_system","model_res_currency","group_system",1,1,1,1
"access_res_currency_rate_group_system","res_currency_rate group_system","model_res_currency_rate","group_system",1,1,1,1
"access_res_groups_group_erp_manager","res_groups group_erp_manager","model_res_groups","group_erp_manager",1,1,1,1