Merge pull request #885 from odoo-dev/master-shop-fp

Fixes for perf issues /shop + cleaning pricelists & currencies
This commit is contained in:
Fabien Pinckaers 2014-07-02 20:34:21 +02:00
commit 0c702bdfa7
13 changed files with 71 additions and 94 deletions

View File

@ -43,5 +43,3 @@ class res_currency_account(osv.osv):
rate = float(tot2)/float(tot1)
return rate
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -48,7 +48,6 @@ access_account_fiscalyear_partner_manager,account.fiscalyear.partnermanager,mode
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

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
48 access_account_fiscalyear_employee account.fiscalyear employee model_account_fiscalyear base.group_user 1 0 0 0
49 access_res_currency_account_manager res.currency account manager base.model_res_currency group_account_manager 1 1 1 1
50 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
51 access_account_invoice_user account.invoice user model_account_invoice base.group_user 1 0 0 0
52 access_account_invoice_user account.invoice.line user model_account_invoice_line base.group_user 1 0 0 0
53 access_account_payment_term_partner_manager account.payment.term partner manager model_account_payment_term base.group_user 1 0 0 0

View File

@ -3,4 +3,5 @@ access_mail_message_portal,mail.message.portal,mail.model_mail_message,base.grou
access_mail_mail_portal,mail.mail.portal,mail.model_mail_mail,base.group_portal,1,1,1,0
access_mail_notification_portal,mail.notification.portal,mail.model_mail_notification,base.group_portal,1,1,1,0
access_mail_followers_portal,mail.followers.portal,mail.model_mail_followers,base.group_portal,1,1,0,0
access_ir_attachment_group_portal,ir.attachment group_portal,base.model_ir_attachment,base.group_portal,1,0,1,0
access_ir_attachment_group_portal,ir.attachment group_portal,base.model_ir_attachment,base.group_portal,1,0,1,0
access_ir_ui_menu_group_portal","ir_ui_menu group_portal","base.model_ir_ui_menu",base.group_portal,1,0,0,0

Can't render this file because it contains an unexpected character in line 7 and column 31.

View File

@ -43,6 +43,10 @@ class price_type(osv.osv):
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:

View File

@ -240,11 +240,12 @@ class website(osv.osv):
def is_publisher(self, cr, uid, ids, context=None):
Access = self.pool['ir.model.access']
is_website_publisher = Access.check(cr, uid, 'ir.ui.view', 'write', False, context)
is_website_publisher = Access.check(cr, uid, 'ir.ui.view', 'write', False, context=context)
return is_website_publisher
def is_user(self, cr, uid, ids, context=None):
return self.pool['res.users'].has_group(cr, uid, 'base.group_user')
Access = self.pool['ir.model.access']
return Access.check(cr, uid, 'ir.ui.menu', 'read', False, context=context)
def get_template(self, cr, uid, ids, template, context=None):
if isinstance(template, (int, long)):

View File

@ -163,7 +163,11 @@ class website_sale(http.Controller):
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)
@ -181,8 +185,12 @@ class website_sale(http.Controller):
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,
@ -190,18 +198,18 @@ class website_sale(http.Controller):
'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)
@ -225,6 +233,12 @@ class website_sale(http.Controller):
category_list = category_obj.name_get(cr, uid, category_ids, context=context)
category_list = sorted(category_list, key=lambda category: category[1])
pricelist = self.get_pricelist()
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)
if not context.get('pricelist'):
context['pricelist'] = int(self.get_pricelist())
product = template_obj.browse(cr, uid, int(product), context=context)
@ -232,8 +246,9 @@ class website_sale(http.Controller):
values = {
'search': search,
'category': category,
'pricelist': self.get_pricelist(),
'pricelist': pricelist,
'attrib_values': attrib_values,
'compute_currency': compute_currency,
'attrib_set': attrib_set,
'keep': keep,
'category_list': category_list,
@ -265,9 +280,16 @@ class website_sale(http.Controller):
def cart(self, **post):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
order = request.website.sale_get_order()
if 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)
else:
compute_currency = lambda price: price
values = {
'order': order,
'compute_currency': compute_currency,
'suggested_products': [],
}
if order:

View File

@ -120,9 +120,9 @@ class website(orm.Model):
_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):
@ -218,9 +218,4 @@ class website(orm.Model):
'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:

View File

@ -80,7 +80,7 @@
<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) &gt; 0.1">
<t t-if="(compute_currency(product.lst_price) - product.price) &gt; 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",
@ -435,7 +435,7 @@
<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) &gt; 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) &gt; 0.1 else 'display: none;'" style="text-decoration: line-through; white-space: nowrap;"
t-field="product.lst_price"
t-field-options='{
"widget": "monetary",
@ -690,7 +690,7 @@
<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) &gt; 0.1">
<t t-if="(compute_currency(line.product_id.lst_price) - line.price_unit) &gt; 0.01">
<del class="text-danger" style="white-space: nowrap;"
t-field="line.product_id.lst_price" t-field-options='{
"widget": "monetary",
@ -784,7 +784,7 @@
<div class="text-muted" t-field="product.description_sale"/>
</td>
<td>
<t t-if="(website.compute_curency(product.lst_price) - product.price) &gt; 0.1">
<t t-if="(compute_currency(product.lst_price) - product.price) &gt; 0.1">
<del class="text-danger" style="white-space: nowrap;"
t-field="product.lst_price" t-field-options='{
"widget": "monetary",

View File

@ -53,12 +53,18 @@ class website_sale_options(website_sale):
@http.route(['/shop/modal'], type='json', auth="public", methods=['POST'], website=True)
def modal(self, product_id, **kw):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
pricelist = self.get_pricelist()
if not context.get('pricelist'):
context['pricelist'] = int(self.get_pricelist())
context['pricelist'] = int(pricelist)
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)
product = pool['product.product'].browse(cr, uid, int(product_id), context=context)
return request.website._render("website_sale_options.modal", {
'product': product,
'compute_currency': compute_currency,
'get_attribute_value_ids': self.get_attribute_value_ids,
})
})

View File

@ -55,7 +55,7 @@
</div>
</td>
<td>
<span t-attf-class="text-danger oe_default_price" t-att-style="'' if (website.compute_curency(product.lst_price) - product.price) &gt; 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) &gt; 0.1 else 'display: none;'" style="text-decoration: line-through; white-space: nowrap;"
t-field="product.lst_price"
t-field-options='{
"widget": "monetary",
@ -106,7 +106,7 @@
</div>
</td>
<td>
<t t-if="(website.compute_curency(product.lst_price) - product.price) &gt; 0.1">
<t t-if="(compute_currency(product.lst_price) - product.price) &gt; 0.1">
<span class="text-danger" style="text-decoration: line-through; white-space: nowrap;"
t-field="product.lst_price"
t-field-options='{

View File

@ -42,17 +42,12 @@ class res_currency(osv.osv):
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:
@ -194,10 +189,7 @@ class res_currency(osv.osv):
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:
@ -211,10 +203,22 @@ class res_currency(osv.osv):
'at the date: %s') % (currency_symbol, date))
return to_currency.rate/from_currency.rate
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:
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
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 = {}
round=True, context=None):
context = context or {}
if not from_currency_id:
from_currency_id = to_currency_id
if not to_currency_id:
@ -222,25 +226,7 @@ class res_currency(osv.osv):
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):
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),
}
return self._compute(cr, uid, from_currency, to_currency, from_amount, round, context)
class res_currency_rate(osv.osv):
_name = "res.currency.rate"
@ -250,7 +236,6 @@ class res_currency_rate(osv.osv):
'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'),

View File

@ -77,38 +77,5 @@
<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>

View File

@ -35,7 +35,7 @@
"access_ir_sequence_type_group_system","ir_sequence_type group_system","model_ir_sequence_type","group_system",1,1,1,1
"access_ir_translation_all","ir_translation all","model_ir_translation",,1,1,1,1
"access_ir_translation_group_system","ir_translation group_system","model_ir_translation","group_system",1,1,1,1
"access_ir_ui_menu_group_user","ir_ui_menu group_user","model_ir_ui_menu",,1,0,0,0
"access_ir_ui_menu_group_user","ir_ui_menu group_user","model_ir_ui_menu",base.group_user,1,0,0,0
"access_ir_ui_menu_group_system","ir_ui_menu group_system","model_ir_ui_menu","group_system",1,1,1,1
"access_ir_ui_view_group_user","ir_ui_view group_user","model_ir_ui_view",,1,0,0,0
"access_ir_ui_view_group_system","ir_ui_view group_system","model_ir_ui_view","group_system",1,1,1,1
@ -51,7 +51,6 @@
"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

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
35 access_ir_sequence_type_group_system ir_sequence_type group_system model_ir_sequence_type group_system 1 1 1 1
36 access_ir_translation_all ir_translation all model_ir_translation 1 1 1 1
37 access_ir_translation_group_system ir_translation group_system model_ir_translation group_system 1 1 1 1
38 access_ir_ui_menu_group_user ir_ui_menu group_user model_ir_ui_menu base.group_user 1 0 0 0
39 access_ir_ui_menu_group_system ir_ui_menu group_system model_ir_ui_menu group_system 1 1 1 1
40 access_ir_ui_view_group_user ir_ui_view group_user model_ir_ui_view 1 0 0 0
41 access_ir_ui_view_group_system ir_ui_view group_system model_ir_ui_view group_system 1 1 1 1
51 access_res_country_group_group_user res_country_group group_user model_res_country_group group_partner_manager 1 1 1 1
52 access_res_currency_group_all res_currency group_all model_res_currency 1 0 0 0
53 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
54 access_res_currency_group_system res_currency group_system model_res_currency group_system 1 1 1 1
55 access_res_currency_rate_group_system res_currency_rate group_system model_res_currency_rate group_system 1 1 1 1
56 access_res_groups_group_erp_manager res_groups group_erp_manager model_res_groups group_erp_manager 1 1 1 1