[ADD] monetary widget use in website_sale

bzr revid: xmo@openerp.com-20131011131147-plqmc1r5ok4tcrge
This commit is contained in:
Xavier Morel
2013-10-11 15:11:47 +02:00
parent c6c0609577
commit 1208a5bcf5
4 changed files with 114 additions and 17 deletions
+24
View File
@@ -54,6 +54,9 @@ class Field(orm.AbstractModel):
def from_html(self, cr, uid, model, column, element, context=None):
return self.value_from_string(element.text_content().strip())
def qweb_object(self):
return self.pool['website.qweb']
class Integer(orm.AbstractModel):
_name = 'website.qweb.field.integer'
_inherit = ['website.qweb.field']
@@ -176,5 +179,26 @@ class Image(orm.AbstractModel):
return out.getvalue().encode('base64')
class Monetary(orm.AbstractModel):
"""
The website's monetary field/widget can become website-aware, and thus
should be able to use a pricelist somehow available through the session?
Why not directly the qweb context. There's also a method stored in
the ecommerce controller in website_sale, would that one be a good/better
idea? => just eval some string and hope that's a pricelist?
Either way, it also gets the ability to fetch the "company" pricelist
via website.get_current().company_id (or 'res_company' in the qweb context)
The widget then needs to call (ir.currency).compute(from_currency,
to_currency, value) to convert the company's to the user's during display
and the other way around during parsing
"""
_name = 'website.qweb.field.monetary'
_inherit = ['website.qweb.field', 'ir.qweb.field.monetary']
def source_currency(self, cr, uid, options):
assert 'source_currency' not in options,\
u"The source currency is automatically defined by the website" \
u" and must not be provided"
return self.pool['website'].get_current().company_id.currency_id
+1
View File
@@ -2,3 +2,4 @@ import controllers
import website_styles
import product
import website_sale
import website
+71 -17
View File
@@ -113,11 +113,17 @@
<div class="product_price">
<b>
<t t-if="product.product_variant_ids[0].lst_price != product.product_variant_ids[0].price">
<span class="text-danger" style="text-decoration: line-through;">
<t t-esc="product.product_variant_ids[0].lst_price" /> €
<span class="text-danger" style="text-decoration: line-through;"
t-field="product.product_variant_ids[0].lst_price" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'>
</span>&amp;nbsp;
</t>
<t t-esc="product.product_variant_ids[0].price" /> €
<span t-field="product.product_variant_ids[0].price" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/>
</b>
</div>
</div>
@@ -339,7 +345,10 @@
<input type="radio" name="product_id" t-att-value="product.id" t-att-checked="product == product.product_variant_ids[0] or None"/>
<t t-esc="product.variants or ''">Standard</t>
<span class="badge" t-if="product.price_extra">
<t t-esc="product.price_extra > 0 and '+' or ''"/><span t-esc="product.price_extra"/> €
<t t-esc="product.price_extra > 0 and '+' or ''"/><span t-field="product.price_extra" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/>
</span>
</label>
<br/>
@@ -349,10 +358,18 @@
<b>
<t t-if="product.product_variant_ids[0].lst_price != product.product_variant_ids[0].price">
<span class="text-danger" style="text-decoration: line-through;">
<t t-esc="product.product_variant_ids[0].lst_price" /> €
<span t-field="product.product_variant_ids[0].lst_price"
t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/>
</span>&amp;nbsp;
</t>
<h4><b><span class="oe_price" t-esc="product.product_variant_ids[0].price" /> €</b></h4>
<h4><b><span class="oe_price" t-field="product.product_variant_ids[0].price"
t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/></b></h4>
</b>
</div>
<button class="btn btn-primary btn-lg mt8">Add to Cart</button>
@@ -454,9 +471,15 @@
</td>
<td class="text-center">
<div class="text-danger" style="text-decoration: line-through;" t-if="line.product_id.lst_price &gt; line.price_unit">
<t t-esc="line.product_id.lst_price" /> €
<span t-field="line.product_id.lst_price" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/>
</div>
<span t-field="line.price_unit"></span> €
<span t-field="line.price_unit" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/>
</td>
<td>
<div class="input-group">
@@ -486,11 +509,21 @@
<thead>
<tr style="border-top: 1px solid #000">
<th><h3>Total:</h3></th>
<th class="text-right"><h3><t t-esc="website_sale_order and website_sale_order.amount_total or 0"/> €</h3></th>
<th class="text-right"><h3>
<span t-field="website_sale_order.amount_total" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/></h3>
</th>
</tr>
<tr class="text-muted">
<td><abbr title="Taxes may be updated after providing shipping address">Incl. Taxes:</abbr></td>
<td class="text-right"><t t-esc="website_sale_order and website_sale_order.amount_tax or 0"/> €</td>
<td class="text-right">
<span t-field="website_sale_order.amount_tax" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/>
</td>
</tr>
</thead>
</table>
@@ -574,7 +607,10 @@
<div class="text-muted" t-field="product.description_sale"/>
</td>
<td>
<span t-field="product.lst_price"></span> €
<span t-field="product.lst_price" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/>
</td>
<td class="text-center">
<a t-href="./add_cart/?product_id=#{ product.id }"><strong>Add to Cart</strong></a>
@@ -742,11 +778,20 @@
<h3 class="page-header mt16">Your Order <small><a href="/shop/mycart"><span class="icon-arrow-right"/> change</a></small></h3>
<div class="row">
<div class="col-sm-6 text-right">Subtotal:</div>
<div class="col-sm-6"><t t-esc="website_sale_order.amount_untaxed or 0"/> €</div>
<div class="col-sm-6"><span t-esc="website_sale_order.amount_untaxed" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/></div>
<div class="col-sm-6 text-right">Taxes:</div>
<div class="col-sm-6"><t t-esc="website_sale_order.amount_tax or 0"/> €</div>
<div class="col-sm-6"><span t-field="website_sale_order.amount_tax" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/></div>
<div class="col-sm-6 text-right"><h4>Total To Pay:</h4></div>
<div class="col-sm-6"><h4><t t-esc="website_sale_order.amount_total or 0"/> €</h4></div>
<div class="col-sm-6"><h4><span t-field="website_sale_order.amount_total" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/></h4></div>
</div>
<button type="submit" class="btn btn-default btn-primary pull-right mt16" t-if="user_id.id != website.public_user.id">
Confirm <span class="icon-long-arrow-right"/>
@@ -807,7 +852,10 @@
<strong t-field="line.product_id.name"/>
</td>
<td class="text-center">
<span t-field="line.price_unit"></span> €
<span t-field="line.price_unit" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/>
</td>
<td>
<div t-esc="line.product_uom_qty"/>
@@ -823,11 +871,17 @@
<thead>
<tr style="border-top: 1px solid #000">
<th><h3>Total:</h3></th>
<th class="text-right"><h3><t t-esc="website_sale_order and website_sale_order.amount_total or 0"/> €</h3></th>
<th class="text-right"><h3><span t-field="website_sale_order.amount_total" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/></h3></th>
</tr>
<tr class="text-muted">
<td><abbr title="Taxes may be updated after providing shipping address">Incl. Taxes:</abbr></td>
<td class="text-right"><t t-esc="website_sale_order and website_sale_order.amount_tax or 0"/> €</td>
<td class="text-right"><span t-field="website_sale_order.amount_tax" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/></td>
</tr>
</thead>
</table>
+18
View File
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from openerp.osv import orm, fields
from openerp.addons.web import http
class Website(orm.Model):
_inherit = 'website'
def _get_pricelist(self, cr, uid, ids, field_name, arg, context=None):
# FIXME: oh god kill me now
pricelist_id = http.request.httprequest.session['ecommerce_pricelist']
return dict.fromkeys(
ids, self.pool['product.pricelist'].browse(
cr, uid, pricelist_id, context=context))
_columns = {
'pricelist_id': fields.function(
_get_pricelist, type='many2one', obj='product.pricelist')
}