Skip to content

Commit

Permalink
[FIX] website_sale: sale_get_order force_create
Browse files Browse the repository at this point in the history
Previously, if there was a sale_order_id but it was wrong,
like when the sale order was deleted for example, the function
didn't return a sale order, even with force_create=True.

It used to pass the first 'if' as sale_order_id had a value, so
no new sale order was created. However, as sometimes the id was
referring to a non-existant sale_order, a sale_order.exists() test
was used later, resulting in the function sometimes returning None,
even with force_create = True.

Proposed solution is to test the existence of the browse record with
the given id earlier, instead of testing the existence of the id itself.
  • Loading branch information
dmo-odoo committed Oct 6, 2015
1 parent 25ea23e commit 6b6d731
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions addons/website_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ def sale_product_domain(self, cr, uid, ids, context=None):
def sale_get_order(self, cr, uid, ids, force_create=False, code=None, update_pricelist=None, context=None):
sale_order_obj = self.pool['sale.order']
sale_order_id = request.session.get('sale_order_id')
sale_order = None
sale_order = sale_order_obj.browse(cr, SUPERUSER_ID, sale_order_id, context=context)
# create so if needed
if not sale_order_id and (force_create or code):
if not sale_order.exists() and (force_create or code):
# TODO cache partner_id session
partner = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id

Expand All @@ -146,15 +146,11 @@ def sale_get_order(self, cr, uid, ids, force_create=False, code=None, update_pri
values = sale_order_obj.onchange_partner_id(cr, SUPERUSER_ID, [], partner.id, context=context)['value']
sale_order_obj.write(cr, SUPERUSER_ID, [sale_order_id], values, context=context)
request.session['sale_order_id'] = sale_order_id
if sale_order_id:
sale_order = sale_order_obj.browse(cr, SUPERUSER_ID, sale_order_id, context=context)

if sale_order.exists():
# TODO cache partner_id session
partner = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id

sale_order = sale_order_obj.browse(cr, SUPERUSER_ID, sale_order_id, context=context)
if not sale_order.exists():
request.session['sale_order_id'] = None
return None

# check for change of pricelist with a coupon
if code and code != sale_order.pricelist_id.code:
pricelist_ids = self.pool['product.pricelist'].search(cr, SUPERUSER_ID, [('code', '=', code)], context=context)
Expand Down Expand Up @@ -197,6 +193,10 @@ def sale_get_order(self, cr, uid, ids, force_create=False, code=None, update_pri
if (code and code != sale_order.pricelist_id.code) or sale_order.partner_id.id != partner.id:
sale_order = sale_order_obj.browse(cr, SUPERUSER_ID, sale_order.id, context=context)

else:
request.session['sale_order_id'] = None
return None

return sale_order

def sale_get_transaction(self, cr, uid, ids, context=None):
Expand Down

0 comments on commit 6b6d731

Please sign in to comment.