[FIX] website_sale: apply fiscal position on change product id and update cart.
[IMP] sale: apply fiscal position of the partner if they are not fiscal position defined bzr revid: chm@openerp.com-20140428093609-8z8my9vj322shcll
This commit is contained in:
parent
edaed14f3f
commit
bb2ebf7cb9
|
@ -862,15 +862,15 @@ class sale_order_line(osv.osv):
|
|||
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
|
||||
context = context or {}
|
||||
lang = lang or context.get('lang',False)
|
||||
if not partner_id:
|
||||
if not partner_id:
|
||||
raise osv.except_osv(_('No Customer Defined!'), _('Before choosing a product,\n select a customer in the sales form.'))
|
||||
warning = {}
|
||||
product_uom_obj = self.pool.get('product.uom')
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
product_obj = self.pool.get('product.product')
|
||||
context = {'lang': lang, 'partner_id': partner_id}
|
||||
if partner_id:
|
||||
lang = partner_obj.browse(cr, uid, partner_id).lang
|
||||
partner = partner_obj.browse(cr, uid, partner_id)
|
||||
lang = partner.lang
|
||||
context_partner = {'lang': lang, 'partner_id': partner_id}
|
||||
|
||||
if not product:
|
||||
|
@ -896,7 +896,12 @@ class sale_order_line(osv.osv):
|
|||
uos = False
|
||||
else:
|
||||
uos = False
|
||||
fpos = fiscal_position and self.pool.get('account.fiscal.position').browse(cr, uid, fiscal_position) or False
|
||||
|
||||
fpos = False
|
||||
if not fiscal_position:
|
||||
fpos = partner.property_account_position or False
|
||||
else:
|
||||
fpos = self.pool.get('account.fiscal.position').browse(cr, uid, fiscal_position)
|
||||
if update_tax: #The quantity only have changed
|
||||
result['tax_id'] = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, product_obj.taxes_id)
|
||||
|
||||
|
|
|
@ -377,8 +377,8 @@ class website_sale(http.Controller):
|
|||
if request.uid != request.website.user_id.id:
|
||||
partner_id = orm_user.browse(cr, SUPERUSER_ID, uid, context=context).partner_id.id
|
||||
elif order.partner_id:
|
||||
domain = [("active", "=", False), ("partner_id", "=", order.partner_id.id)]
|
||||
user_ids = request.registry['res.users'].search(cr, SUPERUSER_ID, domain, context=context)
|
||||
user_ids = request.registry['res.users'].search(cr, SUPERUSER_ID,
|
||||
[("partner_id", "=", order.partner_id.id)], context=dict(context or {}, active_test=False))
|
||||
if not user_ids or request.website.user_id.id not in user_ids:
|
||||
partner_id = order.partner_id.id
|
||||
|
||||
|
|
|
@ -52,46 +52,43 @@ class sale_order(osv.Model):
|
|||
""" Add or set product quantity, add_qty can be negative """
|
||||
sol = self.pool.get('sale.order.line')
|
||||
|
||||
def product_id_change(so, product_id):
|
||||
values = sol.product_id_change(cr, SUPERUSER_ID, [],
|
||||
pricelist=so.pricelist_id.id,
|
||||
product=product_id,
|
||||
partner_id=so.partner_id.id,
|
||||
context=context
|
||||
)['value']
|
||||
values['name'] = "%s: %s" % (product.name, product.variants) if product.variants else product.name
|
||||
values['product_id'] = product_id
|
||||
values['order_id'] = so.id
|
||||
if values.get('tax_id') != None:
|
||||
values['tax_id'] = [(6, 0, values['tax_id'])]
|
||||
return values
|
||||
|
||||
for so in self.browse(cr, uid, ids, context=context):
|
||||
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
|
||||
line_id = so._cart_find_product_line(product_id)
|
||||
|
||||
# Create line if no line with product_id can be located
|
||||
if not line_id:
|
||||
values = sol.product_id_change(cr, SUPERUSER_ID, [],
|
||||
pricelist=so.pricelist_id.id,
|
||||
product=product_id,
|
||||
partner_id=so.partner_id.id,
|
||||
context=context
|
||||
)['value']
|
||||
values['name'] = "%s: %s" % (product.name, product.variants) if product.variants else product.name
|
||||
values['product_id'] = product_id
|
||||
values['order_id'] = so.id
|
||||
if values.get('tax_id'):
|
||||
values['tax_id'] = [(6, 0, values['tax_id'])]
|
||||
values = product_id_change(so, product_id)
|
||||
line_id = sol.create(cr, SUPERUSER_ID, values, context=context)
|
||||
|
||||
# compute new quantity
|
||||
quantity = 0
|
||||
if set_qty:
|
||||
quantity = set_qty
|
||||
else:
|
||||
quantity = sol.browse(cr, SUPERUSER_ID, line_id, context=context).product_uom_qty + add_qty
|
||||
elif add_qty != None:
|
||||
quantity = sol.browse(cr, SUPERUSER_ID, line_id, context=context).product_uom_qty + (add_qty or 0)
|
||||
|
||||
# Remove zero of negative lines
|
||||
if quantity <= 0:
|
||||
sol.unlink(cr, SUPERUSER_ID, line_id, context=context)
|
||||
sol.unlink(cr, SUPERUSER_ID, [line_id], context=context)
|
||||
else:
|
||||
# update line
|
||||
values = sol.product_id_change(cr, SUPERUSER_ID, [],
|
||||
pricelist=so.pricelist_id.id,
|
||||
product=product_id,
|
||||
partner_id=so.partner_id.id,
|
||||
context=context
|
||||
)['value']
|
||||
values['name'] = "%s: %s" % (product.name, product.variants) if product.variants else product.name
|
||||
values = product_id_change(so, product_id)
|
||||
values['product_uom_qty'] = quantity
|
||||
if values.get('tax_id'):
|
||||
values['tax_id'] = [(6, 0, values['tax_id'])]
|
||||
sol.write(cr, SUPERUSER_ID, [line_id], values, context=context)
|
||||
|
||||
return quantity
|
||||
|
|
Loading…
Reference in New Issue