Skip to content
Permalink
Browse files

[ADD] website_sale: manage pricelist by website.

Allow to specify which pricelist can be used on wich website for which countries
  • Loading branch information...
JKE-be committed Apr 24, 2015
1 parent 5612b5f commit bcb395616b6d865ab2315c730a9af76132b66493
@@ -105,14 +105,7 @@ def __call__(self, path=None, **kw):


def get_pricelist():
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
sale_order = context.get('sale_order')
if sale_order:
pricelist = sale_order.pricelist_id
else:
partner = pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id
pricelist = partner.property_product_pricelist
return pricelist
return request.website.get_current_pricelist()

class website_sale(http.Controller):

@@ -138,6 +131,13 @@ def get_attribute_value_ids(self, product):

return attribute_value_ids

@http.route(['/shop/change_pricelist/<model("product.pricelist"):pl_id>'], type='http', auth="public", website=True)
def pricelist_change(self, pl_id, **post):
if request.website.is_pricelist_available(pl_id.id, context=request.context):
request.session['website_sale_current_pl'] = pl_id.id
request.website.sale_get_order(force_pricelist=pl_id.id, context=request.context)
return request.redirect(request.httprequest.referrer or '/shop')

@http.route(['/shop',
'/shop/page/<int:page>',
'/shop/category/<model("product.public.category"):category>',
@@ -305,7 +305,12 @@ def product_comment(self, product_template_id, **post):

@http.route(['/shop/pricelist'], type='http', auth="public", website=True)
def pricelist(self, promo, **post):
cr, uid, context = request.cr, request.uid, request.context
cr, uid, pool, context = request.cr, request.uid, request.registry, request.context
pl = pool['product.pricelist'].search(cr, SUPERUSER_ID, [('code', '=', promo)], context=context)
if pl:
if not request.website.is_pricelist_available(pl[0], context=context):
return request.redirect("/shop/cart?code_not_available=1")

request.website.sale_get_order(code=promo, context=context)
return request.redirect("/shop/cart")

@@ -331,11 +336,13 @@ def cart(self, **post):
_order = order.with_context(pricelist=order.pricelist_id.id)
values['suggested_products'] = _order._cart_accessories()

if post.get('code_not_available'):
values['code_not_available'] = post.get('code_not_available')

return request.website.render("website_sale.cart", values)

@http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True)
def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
cr, uid, context = request.cr, request.uid, request.context
request.website.sale_get_order(force_create=1)._cart_update(product_id=int(product_id), add_qty=float(add_qty), set_qty=float(set_qty))
return request.redirect("/shop/cart")

@@ -660,7 +667,6 @@ def confirm_order(self, **post):
request.session['sale_last_order_id'] = order.id

request.website.sale_get_order(update_pricelist=True, context=context)

return request.redirect("/shop/payment")

#------------------------------------------------------
@@ -993,6 +999,6 @@ def get_unit_price(self, product_ids, add_qty, **kw):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
products = pool['product.product'].browse(cr, uid, product_ids, context=context)
partner = pool['res.users'].browse(cr, uid, uid, context=context).partner_id
pricelist_id = request.session.get('sale_order_code_pricelist_id') or partner.property_product_pricelist.id
pricelist_id = request.website.get_current_pricelist(context=context).id
prices = pool['product.pricelist'].price_rule_get_multi(cr, uid, [], [(product, add_qty, partner) for product in products], context=context)
return {product_id: prices[product_id][pricelist_id][0] for product_id in product_ids}
@@ -33,9 +33,12 @@
<field name="member_ids" eval="[(4, ref('base.user_root'))]"/>
<field name="use_quotations" eval="False"/>
</record>
<record id="wlist0" model="website_pricelist">
<field name="selectable" eval="True" />
<field name="website_id" ref="website.default_website" />
<field name="pricelist_id" ref='product.list0' />
<field name="country_group_ids" eval="[(6,0,[ref('base.europe')])]" />

<record model="website" id="website.default_website">
<field name="salesteam_id" ref="website.salesteam_website_sales"/>
</record>
</data>
</openerp>
@@ -785,5 +785,70 @@ Weight: 1.1 ounces</field>
<field name="public_categ_ids" eval="[(6,0,[ref('product.Components')])]"/>
</record>


<record id="list_christmas" model="product.pricelist">
<field name="name">Christmas Pricelist</field>
<field name="type">sale</field>
</record>
<record id="ver_christmas" model="product.pricelist.version">
<field name="pricelist_id" ref="list_christmas"/>
<field name="name">Christmas Pricelist Version</field>
</record>
<record id="item_christmas" model="product.pricelist.item">
<field name="price_version_id" ref="ver_christmas"/>
<field name="base" ref="product.list_price"/>
<field name="price_discount">-0.2</field>
<field name="sequence">10</field>
<field name="name">Christmas Pricelist Line</field>
</record>

<record id="list_benelux" model="product.pricelist">
<field name="name">Benelux Pricelist</field>
<field name="type">sale</field>
</record>
<record id="ver_benelux" model="product.pricelist.version">
<field name="pricelist_id" ref="list_benelux"/>
<field name="name">Benelux Pricelist Version</field>
</record>
<record id="item_benelux" model="product.pricelist.item">
<field name="price_version_id" ref="ver_benelux"/>
<field name="base" ref="product.list_price"/>
<field name="price_discount">-0.1</field>
<field name="sequence">10</field>
<field name="name">Benelux Pricelist Line</field>
</record>

<record id="benelux" model="res.country.group">
<field name="name">BeNeLux</field>
<field name="country_ids" eval="[(6,0,[
ref('base.be'),ref('base.lu'),ref('base.nl')])]"/>
</record>

<record id="US_CA" model="res.country.group">
<field name="name">US-CA</field>
<field name="country_ids" eval="[(6,0,[
ref('base.us'),ref('base.ca')])]"/>
</record>

<record id="wlist-US" model="website_pricelist">
<field name="selectable" eval="True" />
<field name="website_id" ref="website.default_website" />
<field name="pricelist_id" ref='product.list0' />
<field name="country_group_ids" eval="[(6,0,[ref('US_CA')])]" />
</record>

<record id="wlist-CHRISTMAS" model="website_pricelist">
<field name="selectable" eval="False" />
<field name="website_id" ref="website.default_website" />
<field name="pricelist_id" ref='list_christmas' />
<field name="country_group_ids" eval="[(6,0,[ref('benelux')])]" />
</record>

<record id="wlist-BENELUX" model="website_pricelist">
<field name="selectable" eval="True" />
<field name="website_id" ref="website.default_website" />
<field name="pricelist_id" ref='list_benelux' />
<field name="country_group_ids" eval="[(6,0,[ref('benelux')])]" />
</record>
</data>
</openerp>
Oops, something went wrong.

0 comments on commit bcb3956

Please sign in to comment.
You can’t perform that action at this time.