=== modified file 'bin/addons/account_override/wizard/split_invoice.py'
--- bin/addons/account_override/wizard/split_invoice.py 2020-04-20 08:28:46 +0000
+++ bin/addons/account_override/wizard/split_invoice.py 2021-01-12 10:43:24 +0000
@@ -63,6 +63,7 @@
invoice_origin_id = wizard.invoice_id.id
inv_obj = self.pool.get('account.invoice')
invl_obj = self.pool.get('account.invoice.line')
+ wiz_line_obj = self.pool.get('wizard.split.invoice.lines')
# Test lines
if not wizard.invoice_line_ids:
@@ -91,18 +92,26 @@
if not new_inv_id:
raise osv.except_osv(_('Error'), _('The creation of a new invoice failed.'))
- # Delete new lines
- for wiz_line in wizard.invoice_line_ids:
- if wiz_line.invoice_line_id:
- # create values for the new invoice line
- invl_obj.copy(cr, uid, wiz_line.invoice_line_id.id, {'quantity': wiz_line.quantity,'invoice_id': new_inv_id}, context=context)
- # then update old line if exists
- qty = wiz_line.invoice_line_id.quantity - wiz_line.quantity
- # If quantity superior to 0, then write old line, if 0 then delete line
- if qty > 0:
- invl_obj.write(cr, uid, [wiz_line.invoice_line_id.id], {'quantity': qty}, context=context)
- elif qty == 0:
- invl_obj.unlink(cr, uid, [wiz_line.invoice_line_id.id], context=context)
+ inv_lines = wizard.invoice_id and wizard.invoice_id.invoice_line or []
+ inv_lines_in_wiz = [wiz_line.invoice_line_id.id for wiz_line in wizard.invoice_line_ids]
+ for inv_line in inv_lines:
+ if inv_line.id not in inv_lines_in_wiz:
+ # UC1: the line has been deleted in the wizard: add it in the new invoice, and then remove it from the original one
+ invl_obj.copy(cr, uid, inv_line.id, {'invoice_id': new_inv_id}, context=context)
+ invl_obj.unlink(cr, uid, [inv_line.id], context=context)
+ else:
+ wiz_line_ids = wiz_line_obj.search(cr, uid,
+ [('invoice_line_id', '=', inv_line.id),
+ ('wizard_id', '=', wizard.id)], # in case the wiz. is used several times on the same line
+ limit=1, context=context)
+ if wiz_line_ids:
+ wiz_line_id = wiz_line_ids[0]
+ wiz_line_qty = wiz_line_obj.browse(cr, uid, wiz_line_id, fields_to_fetch=['quantity'], context=context).quantity or 0.0
+ diff_qty = (inv_line.quantity or 0.0) - wiz_line_qty
+ if abs(diff_qty) > 10**-3: # UC2: line unchanged in the wizard: nothing to do, i.e. keep it in the original invoice
+ # UC3: quantity has been modified: write the new qty in the original inv., and create a line for the diff in the new one
+ invl_obj.write(cr, uid, [inv_line.id], {'quantity': wiz_line_qty}, context=context)
+ invl_obj.copy(cr, uid, inv_line.id, {'invoice_id': new_inv_id, 'quantity': diff_qty}, context=context)
# Calculate total for invoices
invoice_ids.append(wizard.invoice_id.id)
@@ -111,6 +120,7 @@
return { 'type' : 'ir.actions.act_window_close', 'active_id' : new_inv_id, 'invoice_ids': invoice_ids}
+
wizard_split_invoice()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== modified file 'bin/addons/account_override/wizard/split_invoice.xml'
--- bin/addons/account_override/wizard/split_invoice.xml 2014-02-28 10:03:08 +0000
+++ bin/addons/account_override/wizard/split_invoice.xml 2021-01-12 10:43:24 +0000
@@ -9,7 +9,7 @@
form
-
+
=== modified file 'bin/osv/orm.py'
--- bin/osv/orm.py 2020-10-09 14:34:01 +0000
+++ bin/osv/orm.py 2021-01-12 10:43:24 +0000
@@ -2668,18 +2668,11 @@
return [ k for k, v in self._in_memory_sorted_items(cr, user, order, context=context) ]
res = []
- counter = 0
#Find the value of dict
f = False
if result:
for id, data in self._in_memory_sorted_items(cr, user, order, context=context):
data['id'] = id
- # If no offset, give the first entries between 0 and the limit
- if not offset and limit and (counter > int(limit)):
- break
- # If offset, give only entries between offset and the offset+limit
- elif offset and limit and (counter > int(limit + offset)):
- break
f = True
for arg in result:
@@ -2693,22 +2686,17 @@
f = f and val
if f:
- # Increment the counter only if the data matches with the domain
- counter = counter + 1
- if counter > offset:
- res.append(id)
+ res.append(id)
if count:
return len(res)
+ if offset and limit:
+ return res[offset:limit+offset]
if offset:
- off = 0
- while off < offset:
- res.pop(0)
- off += 1
-
- if limit and len(res) > limit:
- return res[:limit]
+ return res[offset:]
+ if limit:
+ return res[0:limit]
return res or []