[FIX] website_sale: sale_get_order force_create
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.
This commit is contained in:
parent
25ea23eb31
commit
6b6d7310c0
|
@ -129,9 +129,9 @@ class website(orm.Model):
|
|||
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
|
||||
|
||||
|
@ -146,15 +146,11 @@ class website(orm.Model):
|
|||
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)
|
||||
|
@ -197,6 +193,10 @@ class website(orm.Model):
|
|||
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):
|
||||
|
|
Loading…
Reference in New Issue