Merge lp:~scigghia/account-invoicing/7-adding-free-invoice-line into lp:account-invoicing
- 7-adding-free-invoice-line
- Merge into 7.0-git
Proposed by
Andrea Cometa
Status: | Needs review |
---|---|
Proposed branch: | lp:~scigghia/account-invoicing/7-adding-free-invoice-line |
Merge into: | lp:account-invoicing |
Diff against target: |
463 lines (+426/-0) 7 files modified
free_invoice_line/__init__.py (+25/-0) free_invoice_line/__openerp__.py (+40/-0) free_invoice_line/account/__init__.py (+25/-0) free_invoice_line/account/account.py (+211/-0) free_invoice_line/account/account_view.xml (+17/-0) free_invoice_line/i18n/free_invoice_line.pot (+54/-0) free_invoice_line/i18n/it.po (+54/-0) |
To merge this branch: | bzr merge lp:~scigghia/account-invoicing/7-adding-free-invoice-line |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Pedro Manuel Baeza | Needs Resubmitting | ||
Review via email: mp+233317@code.launchpad.net |
Commit message
Description of the change
Adding module that manage free invoice lines
To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote : | # |
review:
Needs Resubmitting
Unmerged revisions
- 55. By Andrea Cometa
-
[add] free invoice line module
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'free_invoice_line' |
2 | === added file 'free_invoice_line/__init__.py' |
3 | --- free_invoice_line/__init__.py 1970-01-01 00:00:00 +0000 |
4 | +++ free_invoice_line/__init__.py 2014-09-04 08:53:08 +0000 |
5 | @@ -0,0 +1,25 @@ |
6 | +# -*- coding: utf-8 -*- |
7 | +############################################################################## |
8 | +# |
9 | +# OpenERP, Open Source Management Solution |
10 | +# Copyright (c) 2012 Andrea Cometa All Rights Reserved. |
11 | +# www.andreacometa.it |
12 | +# openerp@andreacometa.it |
13 | +# |
14 | +# This program is free software: you can redistribute it and/or modify |
15 | +# it under the terms of the GNU Affero General Public License as |
16 | +# published by |
17 | +# the Free Software Foundation, either version 3 of the License, or |
18 | +# (at your option) any later version. |
19 | +# |
20 | +# This program is distributed in the hope that it will be useful, |
21 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | +# GNU Affero General Public License for more details. |
24 | +# |
25 | +# You should have received a copy of the GNU Affero General Public License |
26 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | +# |
28 | +############################################################################## |
29 | + |
30 | +from . import account |
31 | |
32 | === added file 'free_invoice_line/__openerp__.py' |
33 | --- free_invoice_line/__openerp__.py 1970-01-01 00:00:00 +0000 |
34 | +++ free_invoice_line/__openerp__.py 2014-09-04 08:53:08 +0000 |
35 | @@ -0,0 +1,40 @@ |
36 | +# -*- coding: utf-8 -*- |
37 | +############################################################################## |
38 | +# |
39 | +# OpenERP, Open Source Management Solution |
40 | +# Copyright (c) 2014 Andrea Cometa All Rights Reserved. |
41 | +# www.andreacometa.it |
42 | +# openerp@andreacometa.it |
43 | +# |
44 | +# This program is free software: you can redistribute it and/or modify |
45 | +# it under the terms of the GNU Affero General Public License as |
46 | +# published by |
47 | +# the Free Software Foundation, either version 3 of the License, or |
48 | +# (at your option) any later version. |
49 | +# |
50 | +# This program is distributed in the hope that it will be useful, |
51 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
52 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
53 | +# GNU Affero General Public License for more details. |
54 | +# |
55 | +# You should have received a copy of the GNU Affero General Public License |
56 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
57 | +# |
58 | +############################################################################## |
59 | + |
60 | +{ |
61 | + "name": "Free Invoice Lines", |
62 | + "description": """This module adds 'for free' field to the invoice lines""", |
63 | + "version": "0.1", |
64 | + "depends": ['account'], |
65 | + "category": "Accounting & Finance", |
66 | + "author": "Andrea Cometa", |
67 | + "url": "http://www.andreacometa.it", |
68 | + "data": [ |
69 | + 'account/account_view.xml', |
70 | + ], |
71 | + "installable": True, |
72 | + "auto_install": False, |
73 | + "certificate": "", |
74 | + 'images': [], |
75 | +} |
76 | |
77 | === added directory 'free_invoice_line/account' |
78 | === added file 'free_invoice_line/account/__init__.py' |
79 | --- free_invoice_line/account/__init__.py 1970-01-01 00:00:00 +0000 |
80 | +++ free_invoice_line/account/__init__.py 2014-09-04 08:53:08 +0000 |
81 | @@ -0,0 +1,25 @@ |
82 | +# -*- coding: utf-8 -*- |
83 | +############################################################################## |
84 | +# |
85 | +# OpenERP, Open Source Management Solution |
86 | +# Copyright (c) 2012 Andrea Cometa All Rights Reserved. |
87 | +# www.andreacometa.it |
88 | +# openerp@andreacometa.it |
89 | +# |
90 | +# This program is free software: you can redistribute it and/or modify |
91 | +# it under the terms of the GNU Affero General Public License as |
92 | +# published by |
93 | +# the Free Software Foundation, either version 3 of the License, or |
94 | +# (at your option) any later version. |
95 | +# |
96 | +# This program is distributed in the hope that it will be useful, |
97 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
98 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
99 | +# GNU Affero General Public License for more details. |
100 | +# |
101 | +# You should have received a copy of the GNU Affero General Public License |
102 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
103 | +# |
104 | +############################################################################## |
105 | + |
106 | +from . import account |
107 | |
108 | === added file 'free_invoice_line/account/account.py' |
109 | --- free_invoice_line/account/account.py 1970-01-01 00:00:00 +0000 |
110 | +++ free_invoice_line/account/account.py 2014-09-04 08:53:08 +0000 |
111 | @@ -0,0 +1,211 @@ |
112 | +# -*- coding: utf-8 -*- |
113 | +############################################################################## |
114 | +# |
115 | +# OpenERP, Open Source Management Solution |
116 | +# Copyright (c) 2012 Andrea Cometa All Rights Reserved. |
117 | +# www.andreacometa.it |
118 | +# openerp@andreacometa.it |
119 | +# |
120 | +# This program is free software: you can redistribute it and/or modify |
121 | +# it under the terms of the GNU Affero General Public License as |
122 | +# published by |
123 | +# the Free Software Foundation, either version 3 of the License, or |
124 | +# (at your option) any later version. |
125 | +# |
126 | +# This program is distributed in the hope that it will be useful, |
127 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
128 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
129 | +# GNU Affero General Public License for more details. |
130 | +# |
131 | +# You should have received a copy of the GNU Affero General Public License |
132 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
133 | +# |
134 | +############################################################################## |
135 | + |
136 | +from openerp.osv import fields, orm |
137 | +import decimal_precision as dp |
138 | +from tools.translate import _ |
139 | + |
140 | + |
141 | +class account_invoice_line(orm.Model): |
142 | + _inherit = "account.invoice.line" |
143 | + |
144 | + _columns = { |
145 | + 'free': fields.boolean('For Free'), |
146 | + } |
147 | + |
148 | + |
149 | +class account_invoice(orm.Model): |
150 | + _inherit = 'account.invoice' |
151 | + |
152 | + def _amount_all(self, cr, uid, ids, name, args, context=None): |
153 | + res = {} |
154 | + for invoice in self.browse(cr, uid, ids, context=context): |
155 | + res[invoice.id] = { |
156 | + 'amount_untaxed': 0.0, |
157 | + 'amount_tax': 0.0, |
158 | + 'amount_untaxed_free': 0.0, |
159 | + 'amount_tax_free': 0.0, |
160 | + 'amount_total': 0.0 |
161 | + } |
162 | + lines = {} |
163 | + for line in invoice.invoice_line: |
164 | + res[invoice.id]['amount_untaxed'] += line.price_subtotal |
165 | + if line.free: |
166 | + res[invoice.id]['amount_untaxed_free'] += ( |
167 | + line.price_subtotal) |
168 | + # costruiamo un dizionario chiave=iva e valore=imponibile |
169 | + for tax in line.invoice_line_tax_id: |
170 | + if tax.amount in lines: |
171 | + lines[tax.amount] += line.price_subtotal |
172 | + else: |
173 | + lines[tax.amount] = line.price_subtotal |
174 | + for tl in lines: |
175 | + res[invoice.id]['amount_tax_free'] += lines[tl] * (1 + tl) |
176 | + for line in invoice.tax_line: |
177 | + res[invoice.id]['amount_tax'] += line.amount |
178 | + res[invoice.id]['amount_total'] = ( |
179 | + res[invoice.id]['amount_tax'] + |
180 | + res[invoice.id]['amount_untaxed']) |
181 | + return res |
182 | + |
183 | + def _get_invoice_line(self, cr, uid, ids, context=None): |
184 | + result = {} |
185 | + for line in self.pool['account.invoice.line'].browse(cr, uid, ids, |
186 | + context=context): |
187 | + result[line.invoice_id.id] = True |
188 | + return result.keys() |
189 | + |
190 | + def _get_invoice_tax(self, cr, uid, ids, context=None): |
191 | + result = {} |
192 | + for tax in self.pool['account.invoice.tax'].browse(cr, uid, ids, |
193 | + context=context): |
194 | + result[tax.invoice_id.id] = True |
195 | + return result.keys() |
196 | + |
197 | + _columns = { |
198 | + 'amount_untaxed_free': fields.function( |
199 | + _amount_all, digits_compute=dp.get_precision('Account'), |
200 | + string='"For Free" Amount', |
201 | + store={ |
202 | + 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, |
203 | + ['invoice_line'], 20), |
204 | + 'account.invoice.tax': (_get_invoice_tax, None, 20), |
205 | + 'account.invoice.line': (_get_invoice_line, [ |
206 | + 'price_unit', 'invoice_line_tax_id', 'quantity', |
207 | + 'discount', 'invoice_id'], 20), |
208 | + }, |
209 | + multi='all'), |
210 | + 'amount_tax_free': fields.function( |
211 | + _amount_all, digits_compute=dp.get_precision('Account'), |
212 | + string='"For Free" Tax', |
213 | + store={ |
214 | + 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, |
215 | + ['invoice_line'], 20), |
216 | + 'account.invoice.tax': (_get_invoice_tax, None, 20), |
217 | + 'account.invoice.line': (_get_invoice_line, [ |
218 | + 'price_unit', 'invoice_line_tax_id', 'quantity', |
219 | + 'discount', 'invoice_id'], 20), |
220 | + }, |
221 | + multi='all'), |
222 | + 'amount_untaxed': fields.function( |
223 | + _amount_all, digits_compute=dp.get_precision('Account'), |
224 | + string='Untaxed', |
225 | + store={ |
226 | + 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, |
227 | + ['invoice_line'], 20), |
228 | + 'account.invoice.tax': (_get_invoice_tax, None, 20), |
229 | + 'account.invoice.line': (_get_invoice_line, [ |
230 | + 'price_unit', 'invoice_line_tax_id', 'quantity', |
231 | + 'discount', 'invoice_id'], 20), |
232 | + }, |
233 | + multi='all'), |
234 | + 'amount_tax': fields.function( |
235 | + _amount_all, digits_compute=dp.get_precision('Account'), |
236 | + string='Tax', |
237 | + store={ |
238 | + 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, |
239 | + ['invoice_line'], 20), |
240 | + 'account.invoice.tax': (_get_invoice_tax, None, 20), |
241 | + 'account.invoice.line': (_get_invoice_line, [ |
242 | + 'price_unit', 'invoice_line_tax_id', 'quantity', |
243 | + 'discount', 'invoice_id'], 20), |
244 | + }, |
245 | + multi='all'), |
246 | + 'amount_total': fields.function( |
247 | + _amount_all, digits_compute=dp.get_precision('Account'), |
248 | + string='Total', |
249 | + store={ |
250 | + 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, |
251 | + ['invoice_line'], 20), |
252 | + 'account.invoice.tax': (_get_invoice_tax, None, 20), |
253 | + 'account.invoice.line': (_get_invoice_line, [ |
254 | + 'price_unit', 'invoice_line_tax_id', 'quantity', |
255 | + 'discount', 'invoice_id'], 20), |
256 | + }, |
257 | + multi='all'), |
258 | + } |
259 | + |
260 | + def finalize_invoice_move_lines(self, cr, uid, invoice_browse, move_lines): |
261 | + if invoice_browse.amount_untaxed_free > 0.0: |
262 | + precision = self.pool['decimal.precision'].precision_get(cr, 1, |
263 | + 'Account') |
264 | + precision_diff = round( |
265 | + invoice_browse.amount_tax_free - |
266 | + invoice_browse.amount_untaxed_free, precision) |
267 | + account_id = self.pool['account.invoice.line']._default_account_id( |
268 | + cr, uid, {'type': 'out_invoice'}) |
269 | + if (invoice_browse.amount_untaxed_free == |
270 | + invoice_browse.amount_untaxed): |
271 | + # se imponibile = imponibile omaggio |
272 | + move_lines[-1][2]['account_id'] = account_id |
273 | + move_lines[-1][2]['date_maturity'] = False |
274 | + move_lines[-1][2]['debit'] -= invoice_browse.amount_tax_free |
275 | + |
276 | + # riga imponibile omaggio |
277 | + new_line = { |
278 | + 'analytic_account_id': False, |
279 | + 'tax_code_id': False, |
280 | + 'analytic_lines': [], |
281 | + 'tax_amount': False, |
282 | + 'name': _('"For Free" Amount'), |
283 | + 'ref': '', |
284 | + 'analytics_id': False, |
285 | + 'currency_id': False, |
286 | + 'debit': invoice_browse.amount_untaxed_free, |
287 | + 'product_id': False, |
288 | + 'date_maturity': False, |
289 | + 'credit': False, |
290 | + 'date': move_lines[0][2]['date'], |
291 | + 'amount_currency': 0, |
292 | + 'product_uom_id': False, |
293 | + 'quantity': 1, |
294 | + 'partner_id': move_lines[0][2]['partner_id'], |
295 | + 'account_id': account_id, |
296 | + } |
297 | + move_lines += [(0, 0, new_line)] |
298 | + # riga iva omaggio |
299 | + new_line = { |
300 | + 'analytic_account_id': False, |
301 | + 'tax_code_id': False, |
302 | + 'analytic_lines': [], |
303 | + 'tax_amount': False, |
304 | + 'name': _('"For Free" Tax Amount'), |
305 | + 'ref': '', |
306 | + 'analytics_id': False, |
307 | + 'currency_id': False, |
308 | + 'debit': precision_diff, |
309 | + 'product_id': False, |
310 | + 'date_maturity': False, |
311 | + 'credit': False, |
312 | + 'date': move_lines[0][2]['date'], |
313 | + 'amount_currency': 0, |
314 | + 'product_uom_id': False, |
315 | + 'quantity': 1, |
316 | + 'partner_id': move_lines[0][2]['partner_id'], |
317 | + 'account_id': account_id, |
318 | + } |
319 | + move_lines += [(0, 0, new_line)] |
320 | + return move_lines |
321 | + |
322 | +account_invoice() |
323 | |
324 | === added file 'free_invoice_line/account/account_view.xml' |
325 | --- free_invoice_line/account/account_view.xml 1970-01-01 00:00:00 +0000 |
326 | +++ free_invoice_line/account/account_view.xml 2014-09-04 08:53:08 +0000 |
327 | @@ -0,0 +1,17 @@ |
328 | +<?xml version="1.0" encoding="utf-8"?> |
329 | +<openerp> |
330 | + <data> |
331 | + |
332 | + <record id="free_invoice_line_form" model="ir.ui.view"> |
333 | + <field name="name">account.invoice.form</field> |
334 | + <field name="model">account.invoice</field> |
335 | + <field name="inherit_id" ref="account.invoice_form"/> |
336 | + <field name="arch" type="xml"> |
337 | + <field name="discount" position="after"> |
338 | + <field name="free" /> |
339 | + </field> |
340 | + </field> |
341 | + </record> |
342 | + |
343 | + </data> |
344 | +</openerp> |
345 | |
346 | === added directory 'free_invoice_line/i18n' |
347 | === added file 'free_invoice_line/i18n/free_invoice_line.pot' |
348 | --- free_invoice_line/i18n/free_invoice_line.pot 1970-01-01 00:00:00 +0000 |
349 | +++ free_invoice_line/i18n/free_invoice_line.pot 2014-09-04 08:53:08 +0000 |
350 | @@ -0,0 +1,54 @@ |
351 | +# Translation of OpenERP Server. |
352 | +# This file contains the translation of the following modules: |
353 | +# * free_invoice_line |
354 | +# |
355 | +msgid "" |
356 | +msgstr "" |
357 | +"Project-Id-Version: OpenERP Server 7.0\n" |
358 | +"Report-Msgid-Bugs-To: \n" |
359 | +"POT-Creation-Date: 2014-09-04 08:44+0000\n" |
360 | +"PO-Revision-Date: 2014-09-04 08:44+0000\n" |
361 | +"Last-Translator: <>\n" |
362 | +"Language-Team: \n" |
363 | +"MIME-Version: 1.0\n" |
364 | +"Content-Type: text/plain; charset=UTF-8\n" |
365 | +"Content-Transfer-Encoding: \n" |
366 | +"Plural-Forms: \n" |
367 | + |
368 | +#. module: free_invoice_line |
369 | +#: field:account.invoice,amount_untaxed_free:0 |
370 | +#: code:addons/free_invoice_line/account/account.py:171 |
371 | +#, python-format |
372 | +msgid "\"For Free\" Amount" |
373 | +msgstr "" |
374 | + |
375 | +#. module: free_invoice_line |
376 | +#: field:account.invoice,amount_tax_free:0 |
377 | +msgid "\"For Free\" Tax" |
378 | +msgstr "" |
379 | + |
380 | +#. module: free_invoice_line |
381 | +#: code:addons/free_invoice_line/account/account.py:193 |
382 | +#, python-format |
383 | +msgid "\"For Free\" Tax Amount" |
384 | +msgstr "" |
385 | + |
386 | +#. module: free_invoice_line |
387 | +#: field:account.invoice.line,free:0 |
388 | +msgid "For Free" |
389 | +msgstr "" |
390 | + |
391 | +#. module: free_invoice_line |
392 | +#: code:_description:0 |
393 | +#: model:ir.model,name:free_invoice_line.model_account_invoice |
394 | +#, python-format |
395 | +msgid "Invoice" |
396 | +msgstr "" |
397 | + |
398 | +#. module: free_invoice_line |
399 | +#: code:_description:0 |
400 | +#: model:ir.model,name:free_invoice_line.model_account_invoice_line |
401 | +#, python-format |
402 | +msgid "Invoice Line" |
403 | +msgstr "" |
404 | + |
405 | |
406 | === added file 'free_invoice_line/i18n/it.po' |
407 | --- free_invoice_line/i18n/it.po 1970-01-01 00:00:00 +0000 |
408 | +++ free_invoice_line/i18n/it.po 2014-09-04 08:53:08 +0000 |
409 | @@ -0,0 +1,54 @@ |
410 | +# Translation of OpenERP Server. |
411 | +# This file contains the translation of the following modules: |
412 | +# * free_invoice_line |
413 | +# |
414 | +msgid "" |
415 | +msgstr "" |
416 | +"Project-Id-Version: OpenERP Server 7.0\n" |
417 | +"Report-Msgid-Bugs-To: \n" |
418 | +"POT-Creation-Date: 2014-09-04 08:44+0000\n" |
419 | +"PO-Revision-Date: 2014-09-04 08:44+0000\n" |
420 | +"Last-Translator: <>\n" |
421 | +"Language-Team: \n" |
422 | +"MIME-Version: 1.0\n" |
423 | +"Content-Type: text/plain; charset=UTF-8\n" |
424 | +"Content-Transfer-Encoding: \n" |
425 | +"Plural-Forms: \n" |
426 | + |
427 | +#. module: free_invoice_line |
428 | +#: field:account.invoice,amount_untaxed_free:0 |
429 | +#: code:addons/free_invoice_line/account/account.py:171 |
430 | +#, python-format |
431 | +msgid "\"For Free\" Amount" |
432 | +msgstr "Imponibile Omaggio" |
433 | + |
434 | +#. module: free_invoice_line |
435 | +#: field:account.invoice,amount_tax_free:0 |
436 | +msgid "\"For Free\" Tax" |
437 | +msgstr "Imposte Omaggio" |
438 | + |
439 | +#. module: free_invoice_line |
440 | +#: code:addons/free_invoice_line/account/account.py:193 |
441 | +#, python-format |
442 | +msgid "\"For Free\" Tax Amount" |
443 | +msgstr "Importo imposte omaggio" |
444 | + |
445 | +#. module: free_invoice_line |
446 | +#: field:account.invoice.line,free:0 |
447 | +msgid "For Free" |
448 | +msgstr "Omaggio" |
449 | + |
450 | +#. module: free_invoice_line |
451 | +#: code:_description:0 |
452 | +#: model:ir.model,name:free_invoice_line.model_account_invoice |
453 | +#, python-format |
454 | +msgid "Invoice" |
455 | +msgstr "Fattura" |
456 | + |
457 | +#. module: free_invoice_line |
458 | +#: code:_description:0 |
459 | +#: model:ir.model,name:free_invoice_line.model_account_invoice_line |
460 | +#, python-format |
461 | +msgid "Invoice Line" |
462 | +msgstr "Righe Fattura" |
463 | + |
Hi, Andrea, please submit your contribution to:
https:/ /github. com/OCA/ account- invoicing
instead here.
Regards.