Merge lp:~julie-w/unifield-server/US-7904 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-7904
Merge into: lp:unifield-server
Diff against target: 122 lines (+29/-31)
3 files modified
bin/addons/account_override/wizard/split_invoice.py (+22/-12)
bin/addons/account_override/wizard/split_invoice.xml (+1/-1)
bin/osv/orm.py (+6/-18)
To merge this branch: bzr merge lp:~julie-w/unifield-server/US-7904
Reviewer Review Type Date Requested Status
UniField Reviewer Team 2021-01-12 Pending
Review via email: mp+396136@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:24 +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 in 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:
59
60=== modified file 'bin/addons/account_override/wizard/split_invoice.xml'
61--- bin/addons/account_override/wizard/split_invoice.xml 2014-02-28 10:03:08 +0000
62+++ bin/addons/account_override/wizard/split_invoice.xml 2021-01-12 10:43:24 +0000
63@@ -9,7 +9,7 @@
64 <field name="type">form</field>
65 <field name="arch" type="xml">
66 <label string="Select the lines to be split; the wizard will create a new invoice and adjust the original one." align="0.0"/>
67- <field name="invoice_line_ids" nolabel="1">
68+ <field name="invoice_line_ids" nolabel="1" o2m_selectable="2">
69 <tree editable='bottom' hide_new_button="1">
70 <field name="product_id"/>
71 <field name="description"/>
72
73=== modified file 'bin/osv/orm.py'
74--- bin/osv/orm.py 2020-10-09 14:34:01 +0000
75+++ bin/osv/orm.py 2021-01-12 10:43:24 +0000
76@@ -2668,18 +2668,11 @@
77 return [ k for k, v in self._in_memory_sorted_items(cr, user, order, context=context) ]
78
79 res = []
80- counter = 0
81 #Find the value of dict
82 f = False
83 if result:
84 for id, data in self._in_memory_sorted_items(cr, user, order, context=context):
85 data['id'] = id
86- # If no offset, give the first entries between 0 and the limit
87- if not offset and limit and (counter > int(limit)):
88- break
89- # If offset, give only entries between offset and the offset+limit
90- elif offset and limit and (counter > int(limit + offset)):
91- break
92
93 f = True
94 for arg in result:
95@@ -2693,22 +2686,17 @@
96 f = f and val
97
98 if f:
99- # Increment the counter only if the data matches with the domain
100- counter = counter + 1
101- if counter > offset:
102- res.append(id)
103+ res.append(id)
104
105 if count:
106 return len(res)
107
108+ if offset and limit:
109+ return res[offset:limit+offset]
110 if offset:
111- off = 0
112- while off < offset:
113- res.pop(0)
114- off += 1
115-
116- if limit and len(res) > limit:
117- return res[:limit]
118+ return res[offset:]
119+ if limit:
120+ return res[0:limit]
121
122 return res or []
123

Subscribers

People subscribed via source and target branches