Merge lp:~jfb-tempo-consulting/unifield-server/test-us-5297 into lp:unifield-server

Proposed by jftempo on 2019-06-04
Status: Merged
Merged at revision: 5402
Proposed branch: lp:~jfb-tempo-consulting/unifield-server/test-us-5297
Merge into: lp:unifield-server
Diff against target: 684 lines (+128/-298)
4 files modified
bin/addons/account/invoice.py (+123/-92)
bin/addons/account_override/invoice.py (+0/-83)
bin/addons/analytic_distribution/invoice.py (+0/-116)
bin/addons/res_currency_functional/account_move_line_compute_currency.py (+5/-7)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-server/test-us-5297
Reviewer Review Type Date Requested Status
UniField Reviewer Team 2019-06-04 Pending
Review via email: mp+368336@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/invoice.py'
2--- bin/addons/account/invoice.py 2019-03-14 11:20:01 +0000
3+++ bin/addons/account/invoice.py 2019-06-04 14:20:13 +0000
4@@ -714,6 +714,10 @@
5 default.update({
6 'date_due':False
7 })
8+ inv = self.browse(cr, uid, [id], fields_to_fetch=['analytic_distribution_id'], context=context)[0]
9+ if inv.analytic_distribution_id:
10+ default.update({'analytic_distribution_id': self.pool.get('analytic.distribution').copy(cr, uid, inv.analytic_distribution_id.id, {}, context=context)})
11+
12 return super(account_invoice, self).copy(cr, uid, id, default, context)
13
14 def test_paid(self, cr, uid, ids, *args):
15@@ -753,37 +757,7 @@
16 return (ref or '').replace('/','')
17
18 def _get_analytic_lines(self, cr, uid, id):
19- inv = self.browse(cr, uid, id)
20- cur_obj = self.pool.get('res.currency')
21-
22- company_currency = inv.company_id.currency_id.id
23- if inv.type in ('out_invoice', 'in_refund'):
24- sign = 1
25- else:
26- sign = -1
27-
28- iml = self.pool.get('account.invoice.line').move_line_get(cr, uid, inv.id)
29- for il in iml:
30- if il['account_analytic_id']:
31- if inv.type in ('in_invoice', 'in_refund'):
32- ref = inv.reference
33- else:
34- ref = self._convert_ref(cr, uid, inv.number)
35- if not inv.journal_id.analytic_journal_id:
36- raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (inv.journal_id.name,))
37- il['analytic_lines'] = [(0,0, {
38- 'name': il['name'],
39- 'date': inv['date_invoice'],
40- 'account_id': il['account_analytic_id'],
41- 'unit_amount': il['quantity'],
42- 'amount': cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, il['price'], context={'date': inv.date_invoice}) * sign,
43- 'product_id': il['product_id'],
44- 'product_uom_id': il['uos_id'],
45- 'general_account_id': il['account_id'],
46- 'journal_id': inv.journal_id.analytic_journal_id.id,
47- 'ref': ref,
48- })]
49- return iml
50+ return self.pool.get('account.invoice.line').move_line_get(cr, uid, id)
51
52 def action_date_assign(self, cr, uid, ids, *args):
53 for inv in self.browse(cr, uid, ids):
54@@ -792,15 +766,30 @@
55 self.write(cr, uid, [inv.id], res['value'])
56 return True
57
58- def finalize_invoice_move_lines(self, cr, uid, invoice_browse, move_lines):
59- """finalize_invoice_move_lines(cr, uid, invoice, move_lines) -> move_lines
60- Hook method to be overridden in additional modules to verify and possibly alter the
61- move lines to be created by an invoice, for special cases.
62- :param invoice_browse: browsable record of the invoice that is generating the move lines
63- :param move_lines: list of dictionaries with the account.move.lines (as for create())
64- :return: the (possibly updated) final move_lines to create for this invoice
65- """
66- return move_lines
67+ def finalize_invoice_move_lines(self, cr, uid, inv, line):
68+ """
69+ Hook that changes move line data before write them.
70+ Add a link between partner move line and invoice.
71+ Add invoice document date to data.
72+ """
73+ def is_partner_line(dico):
74+ if isinstance(dico, dict):
75+ if dico:
76+ # In case where no amount_currency filled in, then take debit - credit for amount comparison
77+ amount = dico.get('amount_currency', False) or (dico.get('debit', 0.0) - dico.get('credit', 0.0))
78+ if amount == inv.amount_total and dico.get('partner_id', False) == inv.partner_id.id:
79+ return True
80+ return False
81+ new_line = []
82+ for el in line:
83+ if el[2]:
84+ el[2].update({'document_date': inv.document_date})
85+ if el[2] and is_partner_line(el[2]):
86+ el[2].update({'invoice_partner_link': inv.id})
87+ new_line.append((el[0], el[1], el[2]))
88+ else:
89+ new_line.append(el)
90+ return new_line
91
92 def check_tax_lines(self, cr, uid, inv, compute_taxes, ait_obj):
93 if not inv.tax_line:
94@@ -825,29 +814,18 @@
95
96 def compute_invoice_totals(self, cr, uid, inv, company_currency, ref, invoice_move_lines):
97 total = 0
98- total_currency = 0
99- cur_obj = self.pool.get('res.currency')
100 for i in invoice_move_lines:
101- if inv.currency_id.id != company_currency:
102- i['currency_id'] = inv.currency_id.id
103- i['amount_currency'] = i['price']
104- i['price'] = cur_obj.compute(cr, uid, inv.currency_id.id,
105- company_currency, i['price'],
106- context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')})
107- else:
108- i['amount_currency'] = False
109- i['currency_id'] = False
110+ i['currency_id'] = inv.currency_id.id
111+ i['amount_currency'] = i['price']
112 i['ref'] = ref
113 if inv.type in ('out_invoice','in_refund'):
114- total += i['price']
115- total_currency += i['amount_currency'] or i['price']
116- i['price'] = - i['price']
117+ i['price'] = -i['price']
118+ i['amount_currency'] = - i['amount_currency']
119 i['change_sign'] = True
120 else:
121- total -= i['price']
122- total_currency -= i['amount_currency'] or i['price']
123 i['change_sign'] = False
124- return total, total_currency, invoice_move_lines
125+ total -= i['amount_currency']
126+ return total, invoice_move_lines
127
128 def inv_line_characteristic_hashcode(self, invoice, invoice_line):
129 """Overridable hashcode generation for invoice lines. Lines having the same hashcode
130@@ -881,21 +859,25 @@
131 line.append((0,0,val))
132 return line
133
134- def _hook_period_id(self, cr, uid, inv, context={}):
135+ def _hook_period_id(self, cr, uid, inv, context=None):
136 """
137- Redefine period from invoice date
138+ Give matches period that are not draft and not HQ-closed from given date.
139+ Do not use special periods as period 13, 14 and 15.
140 """
141 # Some verifications
142 if not context:
143 context = {}
144 if not inv:
145 return False
146- return self.pool.get('account.period').search(cr, uid, [('date_start','<=',inv.date_invoice or time.strftime('%Y-%m-%d')),('date_stop','>=',inv.date_invoice or time.strftime('%Y-%m-%d')), ('company_id', '=', inv.company_id.id)])
147+ # NB: there is some period state. So we define that we choose only open period (so not draft and not done)
148+ res = self.pool.get('account.period').search(cr, uid, [('date_start','<=',inv.date_invoice or time.strftime('%Y-%m-%d')),
149+ ('date_stop','>=',inv.date_invoice or time.strftime('%Y-%m-%d')), ('state', 'not in', ['created', 'done']),
150+ ('company_id', '=', inv.company_id.id), ('special', '=', False)], context=context, order="date_start ASC, name ASC")
151+ return res
152
153 def action_move_create(self, cr, uid, ids, *args):
154 """Creates invoice related analytics and financial move lines"""
155 ait_obj = self.pool.get('account.invoice.tax')
156- cur_obj = self.pool.get('res.currency')
157 context = {}
158 for inv in self.browse(cr, uid, ids):
159 if not inv.journal_id.sequence_id:
160@@ -967,11 +949,9 @@
161 if inv.type == 'out_refund':
162 entry_type = 'cont_voucher'
163
164- diff_currency_p = inv.currency_id.id <> company_currency
165 # create one move line for the total and possibly adjust the other lines amount
166 total = 0
167- total_currency = 0
168- total, total_currency, iml = self.compute_invoice_totals(cr, uid, inv, company_currency, ref, iml)
169+ total, iml = self.compute_invoice_totals(cr, uid, inv, company_currency, ref, iml)
170 acc_id = inv.account_id.id
171
172 totlines = False
173@@ -979,14 +959,10 @@
174 totlines = self.pool.get('account.payment.term').compute(cr,
175 uid, inv.payment_term.id, total, inv.date_invoice or False)
176 if totlines:
177- res_amount_currency = total_currency
178+ res_amount_currency = total
179 i = 0
180 for t in totlines:
181- if inv.currency_id.id != company_currency:
182- amount_currency = cur_obj.compute(cr, uid,
183- company_currency, inv.currency_id.id, t[1])
184- else:
185- amount_currency = False
186+ amount_currency = t[1]
187
188 # last line add the diff
189 res_amount_currency -= amount_currency or 0
190@@ -1001,10 +977,8 @@
191 'price': t[1],
192 'account_id': acc_id,
193 'date_maturity': t[0],
194- 'amount_currency': diff_currency_p \
195- and amount_currency or False,
196- 'currency_id': diff_currency_p \
197- and inv.currency_id.id or False,
198+ 'amount_currency': t[1],
199+ 'currency_id': inv.currency_id.id,
200 'ref': ref,
201 'is_counterpart': True,
202 })
203@@ -1016,10 +990,8 @@
204 'price': total,
205 'account_id': acc_id,
206 'date_maturity': inv.date_due or False,
207- 'amount_currency': diff_currency_p \
208- and total_currency or False,
209- 'currency_id': diff_currency_p \
210- and inv.currency_id.id or False,
211+ 'amount_currency': total,
212+ 'currency_id': inv.currency_id.id,
213 'ref': ref,
214 'reference': ref, # UTP-594: Use both ref and reference
215 'is_counterpart': True,
216@@ -1087,8 +1059,8 @@
217 'partner_id': part,
218 'name': x['name'][:64],
219 'date': date,
220- 'debit': x['price']>0 and x['price'],
221- 'credit': x['price']<0 and -x['price'],
222+ 'debit_currency': x['price']>0 and x['price'],
223+ 'credit_currency': x['price']<0 and -x['price'],
224 'account_id': x['account_id'],
225 'analytic_lines': x.get('analytic_lines', []),
226 'amount_currency': x.get('change_sign', False) and -x.get('amount_currency', False) or x.get('amount_currency', False),
227@@ -1103,6 +1075,8 @@
228 'analytic_account_id': x.get('account_analytic_id', False),
229 # UNIFIELD REFACTORISATION: (UF-1536) add new attribute to search which line is the counterpart
230 'is_counterpart': x.get('is_counterpart', False),
231+ 'invoice_line_id': x.get('invoice_line_id', False),
232+ 'analytic_distribution_id': x.get('analytic_distribution_id', False),
233 }
234
235 def action_number(self, cr, uid, ids, context=None):
236@@ -1265,19 +1239,43 @@
237 line['reversed_invoice_line_id'] = line['id'] # store a link to the original invoice line
238 del line['id']
239 del line['invoice_id']
240- for field in ('company_id', 'partner_id', 'account_id', 'product_id',
241- 'uos_id', 'account_analytic_id', 'tax_code_id', 'base_code_id','account_tax_id'):
242- line[field] = line.get(field, False) and line[field][0]
243+ if line.get('move_lines',False):
244+ del line['move_lines']
245+ if line.get('import_invoice_id',False):
246+ del line['import_invoice_id']
247+
248+ if 'analytic_line_ids' in line:
249+ line['analytic_line_ids'] = False
250+
251+ for field in (
252+ 'company_id', 'partner_id', 'account_id', 'product_id',
253+ 'uos_id', 'account_analytic_id', 'tax_code_id', 'base_code_id','account_tax_id',
254+ 'order_line_id', 'sale_order_line_id'
255+ ):
256+ line[field] = line.get(field, False) and line[field][0] or False
257+
258 if 'invoice_line_tax_id' in line:
259 line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]
260+
261+ if 'analytic_distribution_id' in line:
262+ if line.get('analytic_distribution_id', False) and line.get('analytic_distribution_id')[0]:
263+ distrib_id = line.get('analytic_distribution_id')[0]
264+ line['analytic_distribution_id'] = self.pool.get('analytic.distribution').copy(cr, uid, distrib_id, {}) or False
265+ else:
266+ line['analytic_distribution_id'] = False
267+
268 return map(lambda x: (0,0,x), lines)
269
270+
271 def _hook_fields_for_refund(self, cr, uid, *args):
272 """
273 Permits to change fields list to be use for creating invoice refund from an invoice.
274 """
275- res = ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id',
276- 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id']
277+ res = [
278+ 'name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id',
279+ 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id',
280+ 'analytic_distribution_id', 'document_date',
281+ ]
282 return res
283
284 def _hook_fields_m2o_for_refund(self, cr, uid, *args):
285@@ -1285,21 +1283,39 @@
286 Permits to change field that would be use for invoice refund.
287 NB: This fields should be many2one fields.
288 """
289- res = ['address_contact_id', 'address_invoice_id', 'partner_id',
290- 'account_id', 'currency_id', 'payment_term', 'journal_id']
291+ res = [
292+ 'address_contact_id', 'address_invoice_id', 'partner_id',
293+ 'account_id', 'currency_id', 'payment_term', 'journal_id',
294+ 'analytic_distribution_id',
295+ ]
296 return res
297
298 def _hook_refund_data(self, cr, uid, data, *args):
299 """
300- Permits to change data for new refund before their creation
301+ Copy analytic distribution for refund invoice
302 """
303 if not data:
304 return False
305+ if 'analytic_distribution_id' in data:
306+ if data.get('analytic_distribution_id', False):
307+ data['analytic_distribution_id'] = self.pool.get('analytic.distribution').copy(cr, uid, data.get('analytic_distribution_id'), {}) or False
308+ else:
309+ data['analytic_distribution_id'] = False
310 return data
311
312 def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None, document_date=None, context=None):
313 if context is None:
314 context = {}
315+ if isinstance(ids, (int, long)):
316+ ids = [ids]
317+
318+ if date or document_date:
319+ for inv in self.browse(cr, uid, ids, fields_to_fetch=['date_invoice', 'document_date']):
320+ if date and date < inv.date_invoice:
321+ raise osv.except_osv(_('Error'), _("Posting date for the refund is before the invoice's posting date!"))
322+ if document_date and document_date < inv.document_date:
323+ raise osv.except_osv(_('Error'), _("Document date for the refund is before the invoice's document date!"))
324+
325 invoices = self.read(cr, uid, ids, self._hook_fields_for_refund(cr, uid))
326 obj_invoice_line = self.pool.get('account.invoice.line')
327 obj_invoice_tax = self.pool.get('account.invoice.tax')
328@@ -1668,11 +1684,9 @@
329 def move_line_get(self, cr, uid, invoice_id, context=None):
330 res = []
331 tax_obj = self.pool.get('account.tax')
332- cur_obj = self.pool.get('res.currency')
333 if context is None:
334 context = {}
335 inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id, context=context)
336- company_currency = inv.company_id.currency_id.id
337
338 for line in inv.invoice_line:
339 mres = self.move_line_get_item(cr, uid, line, context)
340@@ -1703,7 +1717,7 @@
341 tax_code_found = True
342
343 res[-1]['tax_code_id'] = tax_code_id
344- res[-1]['tax_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, tax_amount, context={'date': inv.date_invoice})
345+ res[-1]['tax_amount'] = tax_amount
346 return res
347
348 def _get_line_name(self, line):
349@@ -1725,8 +1739,11 @@
350 return ''.join((trimmed_name, ' x', qty_str))
351
352 def move_line_get_item(self, cr, uid, line, context=None):
353+ if not context:
354+ context = {}
355+
356 line_name = self._get_line_name(line)
357- return {
358+ res = {
359 'type':'src',
360 'name': line_name,
361 'price_unit':line.price_unit,
362@@ -1737,8 +1754,22 @@
363 'uos_id':line.uos_id.id,
364 'account_analytic_id':line.account_analytic_id.id,
365 'taxes':line.invoice_line_tax_id,
366+ 'invoice_line_id': line.id,
367 }
368
369+ ana_obj = self.pool.get('analytic.distribution')
370+ if line.analytic_distribution_id:
371+ new_distrib_id = ana_obj.copy(cr, uid, line.analytic_distribution_id.id, {}, context=context)
372+ if new_distrib_id:
373+ res['analytic_distribution_id'] = new_distrib_id
374+ # If no distribution on invoice line, take those from invoice and copy it!
375+ elif line.invoice_id and line.invoice_id.analytic_distribution_id:
376+ new_distrib_id = ana_obj.copy(cr, uid, line.invoice_id.analytic_distribution_id.id, {}, context=context)
377+ if new_distrib_id:
378+ res['analytic_distribution_id'] = new_distrib_id
379+
380+ return res
381+
382 account_invoice_line()
383
384 class account_invoice_tax(osv.osv):
385
386=== modified file 'bin/addons/account_override/invoice.py'
387--- bin/addons/account_override/invoice.py 2019-03-14 10:45:48 +0000
388+++ bin/addons/account_override/invoice.py 2019-06-04 14:20:13 +0000
389@@ -500,18 +500,6 @@
390 ' before invoice validation')
391 )
392
393- def _refund_cleanup_lines(self, cr, uid, lines, is_account_inv_line=False, context=None):
394- """
395- Remove useless fields
396- """
397- for line in lines:
398- if line.get('move_lines',False):
399- del line['move_lines']
400- if line.get('import_invoice_id',False):
401- del line['import_invoice_id']
402- res = super(account_invoice, self)._refund_cleanup_lines(cr, uid, lines, is_account_inv_line=is_account_inv_line, context=context)
403- return res
404-
405 def check_po_link(self, cr, uid, ids, context=None):
406 """
407 Check that invoice (only supplier invoices) has no link with a PO. This is because of commitments presence.
408@@ -532,30 +520,6 @@
409 raise osv.except_osv(_('Warning'), _('You cannot cancel or delete a supplier invoice linked to a PO.'))
410 return True
411
412- def _hook_period_id(self, cr, uid, inv, context=None):
413- """
414- Give matches period that are not draft and not HQ-closed from given date.
415- Do not use special periods as period 13, 14 and 15.
416- """
417- # Some verifications
418- if not context:
419- context = {}
420- if not inv:
421- return False
422- # NB: there is some period state. So we define that we choose only open period (so not draft and not done)
423- res = self.pool.get('account.period').search(cr, uid, [('date_start','<=',inv.date_invoice or strftime('%Y-%m-%d')),
424- ('date_stop','>=',inv.date_invoice or strftime('%Y-%m-%d')), ('state', 'not in', ['created', 'done']),
425- ('company_id', '=', inv.company_id.id), ('special', '=', False)], context=context, order="date_start ASC, name ASC")
426- return res
427-
428- def __hook_lines_before_pay_and_reconcile(self, cr, uid, lines):
429- """
430- Add document date to account_move_line before pay and reconcile
431- """
432- for line in lines:
433- if line[2] and 'date' in line[2] and not line[2].get('document_date', False):
434- line[2].update({'document_date': line[2].get('date')})
435- return lines
436
437 def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
438 """
439@@ -1162,41 +1126,6 @@
440 self.check_domain_restrictions(cr, uid, ids, context) # raises an error if one unauthorized element is used
441 return True
442
443- def line_get_convert(self, cr, uid, x, part, date, context=None):
444- """
445- Add these field into invoice line:
446- - invoice_line_id
447- """
448- if not context:
449- context = {}
450- res = super(account_invoice, self).line_get_convert(cr, uid, x, part, date, context)
451- res.update({'invoice_line_id': x.get('invoice_line_id', False)})
452- return res
453-
454- def finalize_invoice_move_lines(self, cr, uid, inv, line):
455- """
456- Hook that changes move line data before write them.
457- Add a link between partner move line and invoice.
458- Add invoice document date to data.
459- """
460- def is_partner_line(dico):
461- if isinstance(dico, dict):
462- if dico:
463- # In case where no amount_currency filled in, then take debit - credit for amount comparison
464- amount = dico.get('amount_currency', False) or (dico.get('debit', 0.0) - dico.get('credit', 0.0))
465- if amount == inv.amount_total and dico.get('partner_id', False) == inv.partner_id.id:
466- return True
467- return False
468- new_line = []
469- for el in line:
470- if el[2]:
471- el[2].update({'document_date': inv.document_date})
472- if el[2] and is_partner_line(el[2]):
473- el[2].update({'invoice_partner_link': inv.id})
474- new_line.append((el[0], el[1], el[2]))
475- else:
476- new_line.append(el)
477- return super(account_invoice, self).finalize_invoice_move_lines(cr, uid, inv, new_line)
478
479 def button_debit_note_import_invoice(self, cr, uid, ids, context=None):
480 """
481@@ -1868,18 +1797,6 @@
482 self.pool.get('account.bank.statement.line').write(cr, uid, [x.id for x in inv.register_line_ids], {'amount': -1 * amount}, context)
483 return res
484
485- def move_line_get_item(self, cr, uid, line, context=None):
486- """
487- Add a link between move line and its invoice line
488- """
489- # some verification
490- if not context:
491- context = {}
492- # update default dict with invoice line ID
493- res = super(account_invoice_line, self).move_line_get_item(cr, uid, line, context=context)
494- res.update({'invoice_line_id': line.id})
495- return res
496-
497 def button_open_analytic_lines(self, cr, uid, ids, context=None):
498 """
499 Return analytic lines linked to this invoice line.
500
501=== modified file 'bin/addons/analytic_distribution/invoice.py'
502--- bin/addons/analytic_distribution/invoice.py 2018-02-07 10:21:30 +0000
503+++ bin/addons/analytic_distribution/invoice.py 2019-06-04 14:20:13 +0000
504@@ -71,100 +71,6 @@
505 raise osv.except_osv(_('Error'), _('Analytic distribution is not valid for "%s"') % invl.name)
506 return True
507
508- def _hook_fields_for_refund(self, cr, uid, *args):
509- """
510- Add these fields to result:
511- - analytic_distribution_id
512- """
513- res = super(account_invoice, self)._hook_fields_for_refund(cr, uid, args)
514- res.append('analytic_distribution_id')
515- res.append('document_date')
516- return res
517-
518- def _hook_fields_m2o_for_refund(self, cr, uid, *args):
519- """
520- Add these fields to result:
521- - analytic_distribution_id
522- """
523- res = super(account_invoice, self)._hook_fields_m2o_for_refund(cr, uid, args)
524- res.append('analytic_distribution_id')
525- return res
526-
527- def _hook_refund_data(self, cr, uid, data, *args):
528- """
529- Copy analytic distribution for refund invoice
530- """
531- if not data:
532- return False
533- if 'analytic_distribution_id' in data:
534- if data.get('analytic_distribution_id', False):
535- data['analytic_distribution_id'] = self.pool.get('analytic.distribution').copy(cr, uid, data.get('analytic_distribution_id'), {}) or False
536- else:
537- data['analytic_distribution_id'] = False
538- return data
539-
540- def _refund_cleanup_lines(self, cr, uid, lines, is_account_inv_line=False, context=None):
541- """
542- Add right analytic distribution values on each lines
543- """
544- res = super(account_invoice, self)._refund_cleanup_lines(cr, uid, lines, is_account_inv_line=is_account_inv_line, context=context)
545- for el in res:
546- if el[2]:
547- # Give analytic distribution on line
548- if 'analytic_distribution_id' in el[2]:
549- if el[2].get('analytic_distribution_id', False) and el[2].get('analytic_distribution_id')[0]:
550- distrib_id = el[2].get('analytic_distribution_id')[0]
551- el[2]['analytic_distribution_id'] = self.pool.get('analytic.distribution').copy(cr, uid, distrib_id, {}) or False
552- else:
553- # default value
554- el[2]['analytic_distribution_id'] = False
555- # Give false analytic lines for 'line' in order not to give an error
556- if 'analytic_line_ids' in el[2]:
557- el[2]['analytic_line_ids'] = False
558- # Give false for (because not needed):
559- # - order_line_id
560- # - sale_order_line_id
561- for field in ['order_line_id', 'sale_order_line_id']:
562- if field in el[2]:
563- el[2][field] = el[2].get(field, False) and el[2][field][0] or False
564- return res
565-
566- def copy(self, cr, uid, inv_id, default=None, context=None):
567- """
568- Copy global distribution and give it to new invoice
569- """
570- if not context:
571- context = {}
572- if not default:
573- default = {}
574- inv = self.browse(cr, uid, [inv_id], context=context)[0]
575- if inv.analytic_distribution_id:
576- new_distrib_id = self.pool.get('analytic.distribution').copy(cr, uid, inv.analytic_distribution_id.id, {}, context=context)
577- if new_distrib_id:
578- default.update({'analytic_distribution_id': new_distrib_id})
579- return super(account_invoice, self).copy(cr, uid, inv_id, default, context)
580-
581- def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None, document_date=None, context=None):
582- """
583- Reverse lines for given invoice
584- """
585- if context is None:
586- context = {}
587- if isinstance(ids, (int, long)):
588- ids = [ids]
589- for inv in self.browse(cr, uid, ids):
590- # Check for dates (refund must be done after invoice)
591- if date and date < inv.date_invoice:
592- raise osv.except_osv(_('Error'), _("Posting date for the refund is before the invoice's posting date!"))
593- if document_date and document_date < inv.document_date:
594- raise osv.except_osv(_('Error'), _("Document date for the refund is before the invoice's document date!"))
595- return super(account_invoice, self).refund(cr, uid, ids, date, period_id, description, journal_id, document_date, context=context)
596-
597- def line_get_convert(self, cr, uid, x, part, date, context=None):
598- res = super(account_invoice, self).line_get_convert(cr, uid, x, part, date, context=context)
599- res['analytic_distribution_id'] = x.get('analytic_distribution_id', False)
600- return res
601-
602 def button_analytic_distribution(self, cr, uid, ids, context=None):
603 """
604 Launch analytic distribution wizard on an invoice
605@@ -393,28 +299,6 @@
606 default.update({'analytic_distribution_id': new_distrib_id})
607 return super(account_invoice_line, self).copy_data(cr, uid, l_id, default, context)
608
609- def move_line_get_item(self, cr, uid, line, context=None):
610- """
611- Give right analytic distribution when creating move lines
612- """
613- # Some verifications
614- if not context:
615- context = {}
616- # Default result
617- res = super(account_invoice_line, self).move_line_get_item(cr, uid, line, context=context)
618- # Update result by copying analytic distribution from invoice line
619- ana_obj = self.pool.get('analytic.distribution')
620- if line.analytic_distribution_id:
621- new_distrib_id = ana_obj.copy(cr, uid, line.analytic_distribution_id.id, {}, context=context)
622- if new_distrib_id:
623- res['analytic_distribution_id'] = new_distrib_id
624- # If no distribution on invoice line, take those from invoice and copy it!
625- elif line.invoice_id and line.invoice_id.analytic_distribution_id:
626- new_distrib_id = ana_obj.copy(cr, uid, line.invoice_id.analytic_distribution_id.id, {}, context=context)
627- if new_distrib_id:
628- res['analytic_distribution_id'] = new_distrib_id
629- return res
630-
631 def button_analytic_distribution(self, cr, uid, ids, context=None):
632 """
633 Launch analytic distribution wizard on an invoice line
634
635=== modified file 'bin/addons/res_currency_functional/account_move_line_compute_currency.py'
636--- bin/addons/res_currency_functional/account_move_line_compute_currency.py 2019-04-30 10:25:06 +0000
637+++ bin/addons/res_currency_functional/account_move_line_compute_currency.py 2019-06-04 14:20:13 +0000
638@@ -557,8 +557,8 @@
639 if vals['date'] < period.get('date_start') or vals['date'] > period.get('date_stop'):
640 raise osv.except_osv(_('Warning !'), _('Posting date (%s) is outside of defined period: %s!') % (vals.get('date'), period.get('name') or '',))
641
642- def _update_amount_bis(self, cr, uid, vals, currency_id, curr_fun, date=False, source_date=False,
643- debit_currency=False, credit_currency=False, context=None):
644+ def _compute_currency_on_create_write(self, cr, uid, vals, currency_id, curr_fun, date=False, source_date=False,
645+ debit_currency=False, credit_currency=False, context=None):
646 if context is None:
647 context = {}
648 newvals = {}
649@@ -573,8 +573,6 @@
650
651 if 'currency_table_id' in context:
652 ctxcurr['currency_table_id'] = context['currency_table_id']
653-# if ctxcurr.get('date', False):
654-# newvals['date'] = ctxcurr['date']
655
656 if context.get('from_web_menu') and (vals.get('debit_currency', False) is not False or vals.get('credit_currency', False) is not False):
657 # use case where one of the booking fields MANUALLY CHANGED IN THE INTERFACE has a value, EVEN IF IT IS 0.00
658@@ -589,7 +587,7 @@
659 newvals['credit_currency'] = cur_obj.compute(cr, uid, curr_fun, currency_id, vals.get('credit') or 0.0, round=True, context=ctxcurr)
660 newvals['debit_currency'] = cur_obj.compute(cr, uid, curr_fun, currency_id, vals.get('debit') or 0.0, round=True, context=ctxcurr)
661 newvals['amount_currency'] = newvals['debit_currency'] - newvals['credit_currency']
662- elif vals.get('amount_currency'):
663+ elif vals.get('amount_currency') not in (None, False):
664 if vals['amount_currency'] < 0:
665 newvals['credit_currency'] = -vals['amount_currency']
666 newvals['debit_currency'] = 0
667@@ -664,7 +662,7 @@
668 # and for revaluation lines (US-1682)
669 if not is_system_period and not newvals.get('is_addendum_line', False) and not \
670 (context.get('sync_update_execution', False) and 'is_revaluated_ok' in newvals and newvals['is_revaluated_ok']):
671- newvals.update(self._update_amount_bis(cr, uid, vals, newvals['currency_id'], curr_fun, date=date_to_compute, context=context))
672+ newvals.update(self._compute_currency_on_create_write(cr, uid, vals, newvals['currency_id'], curr_fun, date=date_to_compute, context=context))
673 return super(account_move_line_compute_currency, self).create(cr, uid, newvals, context, check=check)
674
675 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
676@@ -693,7 +691,7 @@
677 currency_id = vals.get('currency_id') or line.currency_id.id
678 func_currency = line.account_id.company_id.currency_id.id
679 if line.period_id and not line.period_id.is_system and not (context.get('sync_update_execution', False) and line.is_revaluated_ok):
680- newvals.update(self._update_amount_bis(cr, uid, newvals, currency_id, func_currency, date, source_date, line.debit_currency, line.credit_currency, context=context))
681+ newvals.update(self._compute_currency_on_create_write(cr, uid, newvals, currency_id, func_currency, date, source_date, line.debit_currency, line.credit_currency, context=context))
682 res = res and super(account_move_line_compute_currency, self).write(cr, uid, [line.id], newvals, context, check=check, update_check=update_check)
683 # Update addendum line for reconciliation entries if this line is reconciled
684 if vals.get('reconcile_id'):

Subscribers

People subscribed via source and target branches