Merge lp:~julie-w/unifield-server/US-7906 into lp:unifield-server

Proposed by jftempo on 2021-01-12
Status: Merged
Merged at revision: 5911
Proposed branch: lp:~julie-w/unifield-server/US-7906
Merge into: lp:unifield-server
Diff against target: 58 lines (+22/-12)
1 file modified
bin/addons/account_override/wizard/split_invoice.py (+22/-12)
To merge this branch: bzr merge lp:~julie-w/unifield-server/US-7906
Reviewer Review Type Date Requested Status
UniField Reviewer Team 2021-01-12 Pending
Review via email: mp+396135@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/account_override/wizard/split_invoice.py'
2--- bin/addons/account_override/wizard/split_invoice.py 2020-04-20 08:28:46 +0000
3+++ bin/addons/account_override/wizard/split_invoice.py 2021-01-12 10:43:23 +0000
4@@ -63,6 +63,7 @@
5 invoice_origin_id = wizard.invoice_id.id
6 inv_obj = self.pool.get('account.invoice')
7 invl_obj = self.pool.get('account.invoice.line')
8+ wiz_line_obj = self.pool.get('wizard.split.invoice.lines')
9
10 # Test lines
11 if not wizard.invoice_line_ids:
12@@ -91,18 +92,26 @@
13 if not new_inv_id:
14 raise osv.except_osv(_('Error'), _('The creation of a new invoice failed.'))
15
16- # Delete new lines
17- for wiz_line in wizard.invoice_line_ids:
18- if wiz_line.invoice_line_id:
19- # create values for the new invoice line
20- invl_obj.copy(cr, uid, wiz_line.invoice_line_id.id, {'quantity': wiz_line.quantity,'invoice_id': new_inv_id}, context=context)
21- # then update old line if exists
22- qty = wiz_line.invoice_line_id.quantity - wiz_line.quantity
23- # If quantity superior to 0, then write old line, if 0 then delete line
24- if qty > 0:
25- invl_obj.write(cr, uid, [wiz_line.invoice_line_id.id], {'quantity': qty}, context=context)
26- elif qty == 0:
27- invl_obj.unlink(cr, uid, [wiz_line.invoice_line_id.id], context=context)
28+ inv_lines = wizard.invoice_id and wizard.invoice_id.invoice_line or []
29+ inv_lines_in_wiz = [wiz_line.invoice_line_id.id for wiz_line in wizard.invoice_line_ids]
30+ for inv_line in inv_lines:
31+ if inv_line.id not in inv_lines_in_wiz:
32+ # UC1: the line has been deleted in the wizard: add it the new invoice, and then remove it from the original one
33+ invl_obj.copy(cr, uid, inv_line.id, {'invoice_id': new_inv_id}, context=context)
34+ invl_obj.unlink(cr, uid, [inv_line.id], context=context)
35+ else:
36+ wiz_line_ids = wiz_line_obj.search(cr, uid,
37+ [('invoice_line_id', '=', inv_line.id),
38+ ('wizard_id', '=', wizard.id)], # in case the wiz. is used several times on the same line
39+ limit=1, context=context)
40+ if wiz_line_ids:
41+ wiz_line_id = wiz_line_ids[0]
42+ wiz_line_qty = wiz_line_obj.browse(cr, uid, wiz_line_id, fields_to_fetch=['quantity'], context=context).quantity or 0.0
43+ diff_qty = (inv_line.quantity or 0.0) - wiz_line_qty
44+ if abs(diff_qty) > 10**-3: # UC2: line unchanged in the wizard: nothing to do, i.e. keep it in the original invoice
45+ # UC3: quantity has been modified: write the new qty in the original inv., and create a line for the diff in the new one
46+ invl_obj.write(cr, uid, [inv_line.id], {'quantity': wiz_line_qty}, context=context)
47+ invl_obj.copy(cr, uid, inv_line.id, {'invoice_id': new_inv_id, 'quantity': diff_qty}, context=context)
48
49 # Calculate total for invoices
50 invoice_ids.append(wizard.invoice_id.id)
51@@ -111,6 +120,7 @@
52
53 return { 'type' : 'ir.actions.act_window_close', 'active_id' : new_inv_id, 'invoice_ids': invoice_ids}
54
55+
56 wizard_split_invoice()
57
58 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Subscribers

People subscribed via source and target branches