[FIX] point_of_sale: remember tax_ids in pos.order
This avoid the unbalanced account.move created by the pos.session when tax are changed on a saled product during the pos session Closes #5161
This commit is contained in:
committed by
Christophe Simonis
parent
ca8c6bce98
commit
c593a881da
@@ -24,6 +24,8 @@ import time
|
||||
import uuid
|
||||
import sets
|
||||
|
||||
from functools import partial
|
||||
|
||||
from openerp import tools, models
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools import float_is_zero
|
||||
@@ -574,11 +576,12 @@ class pos_order(osv.osv):
|
||||
_order = "id desc"
|
||||
|
||||
def _order_fields(self, cr, uid, ui_order, context=None):
|
||||
process_line = partial(self.pool['pos.order.line']._order_line_fields, cr, uid, context=context)
|
||||
return {
|
||||
'name': ui_order['name'],
|
||||
'user_id': ui_order['user_id'] or False,
|
||||
'session_id': ui_order['pos_session_id'],
|
||||
'lines': ui_order['lines'],
|
||||
'lines': [process_line(l) for l in ui_order['lines']] if ui_order['lines'] else False,
|
||||
'pos_reference':ui_order['name'],
|
||||
'partner_id': ui_order['partner_id'] or False,
|
||||
}
|
||||
@@ -1005,7 +1008,8 @@ class pos_order(osv.osv):
|
||||
inv_line['price_unit'] = line.price_unit
|
||||
inv_line['discount'] = line.discount
|
||||
inv_line['name'] = inv_name
|
||||
inv_line['invoice_line_tax_id'] = [(6, 0, [x.id for x in line.product_id.taxes_id] )]
|
||||
if line.tax_ids:
|
||||
inv_line['invoice_line_tax_id'] = [(6, 0, [x.id for x in line.tax_ids])]
|
||||
inv_line_ref.create(cr, uid, inv_line, context=context)
|
||||
inv_ref.button_reset_taxes(cr, uid, [inv_id], context=context)
|
||||
self.signal_workflow(cr, uid, [order.id], 'invoice')
|
||||
@@ -1142,11 +1146,7 @@ class pos_order(osv.osv):
|
||||
cur = order.pricelist_id.currency_id
|
||||
for line in order.lines:
|
||||
tax_amount = 0
|
||||
taxes = []
|
||||
for t in line.product_id.taxes_id:
|
||||
if t.company_id.id == current_company.id:
|
||||
taxes.append(t)
|
||||
computed_taxes = account_tax_obj.compute_all(cr, uid, taxes, line.price_unit * (100.0-line.discount) / 100.0, line.qty)['taxes']
|
||||
computed_taxes = account_tax_obj.compute_all(cr, uid, line.tax_ids, line.price_unit * (100.0-line.discount) / 100.0, line.qty)['taxes']
|
||||
|
||||
for tax in computed_taxes:
|
||||
tax_amount += cur_obj.round(cr, uid, cur, tax['amount'])
|
||||
@@ -1289,6 +1289,12 @@ class pos_order_line(osv.osv):
|
||||
_description = "Lines of Point of Sale"
|
||||
_rec_name = "product_id"
|
||||
|
||||
def _order_line_fields(self, cr, uid, line, context=None):
|
||||
if 'tax_ids' not in line:
|
||||
product = self.pool['product.product'].browse(cr, uid, line['product_id'], context=context)
|
||||
line['tax_ids'] = [(6, 0, [x.id for x in product.taxes_id])]
|
||||
return line
|
||||
|
||||
def _amount_line_all(self, cr, uid, ids, field_names, arg, context=None):
|
||||
res = dict([(i, {}) for i in ids])
|
||||
account_tax_obj = self.pool.get('account.tax')
|
||||
@@ -1347,6 +1353,7 @@ class pos_order_line(osv.osv):
|
||||
'discount': fields.float('Discount (%)', digits_compute=dp.get_precision('Account')),
|
||||
'order_id': fields.many2one('pos.order', 'Order Ref', ondelete='cascade'),
|
||||
'create_date': fields.datetime('Creation Date', readonly=True),
|
||||
'tax_ids': fields.many2many('account.tax', string='Taxes', readonly=True),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
<field name="qty" on_change="onchange_qty(product_id, discount, qty, price_unit, context)"/>
|
||||
<field name="price_unit" on_change="onchange_qty(product_id, discount, qty, price_unit, context)"/>
|
||||
<field name="discount" on_change="onchange_qty(product_id, discount, qty, price_unit, context)"/>
|
||||
<field name="tax_ids" widget="many2many_tags"/>
|
||||
<field name="price_subtotal"/>
|
||||
<field name="price_subtotal_incl"/>
|
||||
</tree>
|
||||
@@ -1016,4 +1017,3 @@
|
||||
sequence="30"/>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
|
||||
@@ -1001,6 +1001,7 @@ openerp.point_of_sale.load_models = function load_models(instance, module){ //mo
|
||||
price_unit: this.get_unit_price(),
|
||||
discount: this.get_discount(),
|
||||
product_id: this.get_product().id,
|
||||
tax_ids: [[6, false, _.map(this.get_applicable_taxes(), function(tax){ return tax.id; })]],
|
||||
id: this.id,
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user