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

Proposed by jftempo
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 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
=== 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:23 +0000
@@ -63,6 +63,7 @@
63 invoice_origin_id = wizard.invoice_id.id63 invoice_origin_id = wizard.invoice_id.id
64 inv_obj = self.pool.get('account.invoice')64 inv_obj = self.pool.get('account.invoice')
65 invl_obj = self.pool.get('account.invoice.line')65 invl_obj = self.pool.get('account.invoice.line')
66 wiz_line_obj = self.pool.get('wizard.split.invoice.lines')
6667
67 # Test lines68 # Test lines
68 if not wizard.invoice_line_ids:69 if not wizard.invoice_line_ids:
@@ -91,18 +92,26 @@
91 if not new_inv_id:92 if not new_inv_id:
92 raise osv.except_osv(_('Error'), _('The creation of a new invoice failed.'))93 raise osv.except_osv(_('Error'), _('The creation of a new invoice failed.'))
9394
94 # Delete new lines95 inv_lines = wizard.invoice_id and wizard.invoice_id.invoice_line or []
95 for wiz_line in wizard.invoice_line_ids:96 inv_lines_in_wiz = [wiz_line.invoice_line_id.id for wiz_line in wizard.invoice_line_ids]
96 if wiz_line.invoice_line_id:97 for inv_line in inv_lines:
97 # create values for the new invoice line98 if inv_line.id not in inv_lines_in_wiz:
98 invl_obj.copy(cr, uid, wiz_line.invoice_line_id.id, {'quantity': wiz_line.quantity,'invoice_id': new_inv_id}, context=context)99 # UC1: the line has been deleted in the wizard: add it the new invoice, and then remove it from the original one
99 # then update old line if exists100 invl_obj.copy(cr, uid, inv_line.id, {'invoice_id': new_inv_id}, context=context)
100 qty = wiz_line.invoice_line_id.quantity - wiz_line.quantity101 invl_obj.unlink(cr, uid, [inv_line.id], context=context)
101 # If quantity superior to 0, then write old line, if 0 then delete line102 else:
102 if qty > 0:103 wiz_line_ids = wiz_line_obj.search(cr, uid,
103 invl_obj.write(cr, uid, [wiz_line.invoice_line_id.id], {'quantity': qty}, context=context)104 [('invoice_line_id', '=', inv_line.id),
104 elif qty == 0:105 ('wizard_id', '=', wizard.id)], # in case the wiz. is used several times on the same line
105 invl_obj.unlink(cr, uid, [wiz_line.invoice_line_id.id], context=context)106 limit=1, context=context)
107 if wiz_line_ids:
108 wiz_line_id = wiz_line_ids[0]
109 wiz_line_qty = wiz_line_obj.browse(cr, uid, wiz_line_id, fields_to_fetch=['quantity'], context=context).quantity or 0.0
110 diff_qty = (inv_line.quantity or 0.0) - wiz_line_qty
111 if abs(diff_qty) > 10**-3: # UC2: line unchanged in the wizard: nothing to do, i.e. keep it in the original invoice
112 # UC3: quantity has been modified: write the new qty in the original inv., and create a line for the diff in the new one
113 invl_obj.write(cr, uid, [inv_line.id], {'quantity': wiz_line_qty}, context=context)
114 invl_obj.copy(cr, uid, inv_line.id, {'invoice_id': new_inv_id, 'quantity': diff_qty}, context=context)
106115
107 # Calculate total for invoices116 # Calculate total for invoices
108 invoice_ids.append(wizard.invoice_id.id)117 invoice_ids.append(wizard.invoice_id.id)
@@ -111,6 +120,7 @@
111120
112 return { 'type' : 'ir.actions.act_window_close', 'active_id' : new_inv_id, 'invoice_ids': invoice_ids}121 return { 'type' : 'ir.actions.act_window_close', 'active_id' : new_inv_id, 'invoice_ids': invoice_ids}
113122
123
114wizard_split_invoice()124wizard_split_invoice()
115125
116# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:126# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Subscribers

People subscribed via source and target branches