Andrea Cometa has proposed merging lp:~scigghia/account-invoicing/7-adding-free-invoice-line into lp:account-invoicing.
Requested reviews: Account Core Editors (account-core-editors) For more details, see: https://code.launchpad.net/~scigghia/account-invoicing/7-adding-free-invoice-line/+merge/233317 Adding module that manage free invoice lines -- https://code.launchpad.net/~scigghia/account-invoicing/7-adding-free-invoice-line/+merge/233317 Your team Account Core Editors is requested to review the proposed merge of lp:~scigghia/account-invoicing/7-adding-free-invoice-line into lp:account-invoicing.
=== added directory 'free_invoice_line' === added file 'free_invoice_line/__init__.py' --- free_invoice_line/__init__.py 1970-01-01 00:00:00 +0000 +++ free_invoice_line/__init__.py 2014-09-04 08:53:08 +0000 @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (c) 2012 Andrea Cometa All Rights Reserved. +# www.andreacometa.it +# [email protected] +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +from . import account === added file 'free_invoice_line/__openerp__.py' --- free_invoice_line/__openerp__.py 1970-01-01 00:00:00 +0000 +++ free_invoice_line/__openerp__.py 2014-09-04 08:53:08 +0000 @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (c) 2014 Andrea Cometa All Rights Reserved. +# www.andreacometa.it +# [email protected] +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +{ + "name": "Free Invoice Lines", + "description": """This module adds 'for free' field to the invoice lines""", + "version": "0.1", + "depends": ['account'], + "category": "Accounting & Finance", + "author": "Andrea Cometa", + "url": "http://www.andreacometa.it", + "data": [ + 'account/account_view.xml', + ], + "installable": True, + "auto_install": False, + "certificate": "", + 'images': [], +} === added directory 'free_invoice_line/account' === added file 'free_invoice_line/account/__init__.py' --- free_invoice_line/account/__init__.py 1970-01-01 00:00:00 +0000 +++ free_invoice_line/account/__init__.py 2014-09-04 08:53:08 +0000 @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (c) 2012 Andrea Cometa All Rights Reserved. +# www.andreacometa.it +# [email protected] +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +from . import account === added file 'free_invoice_line/account/account.py' --- free_invoice_line/account/account.py 1970-01-01 00:00:00 +0000 +++ free_invoice_line/account/account.py 2014-09-04 08:53:08 +0000 @@ -0,0 +1,211 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (c) 2012 Andrea Cometa All Rights Reserved. +# www.andreacometa.it +# [email protected] +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +from openerp.osv import fields, orm +import decimal_precision as dp +from tools.translate import _ + + +class account_invoice_line(orm.Model): + _inherit = "account.invoice.line" + + _columns = { + 'free': fields.boolean('For Free'), + } + + +class account_invoice(orm.Model): + _inherit = 'account.invoice' + + def _amount_all(self, cr, uid, ids, name, args, context=None): + res = {} + for invoice in self.browse(cr, uid, ids, context=context): + res[invoice.id] = { + 'amount_untaxed': 0.0, + 'amount_tax': 0.0, + 'amount_untaxed_free': 0.0, + 'amount_tax_free': 0.0, + 'amount_total': 0.0 + } + lines = {} + for line in invoice.invoice_line: + res[invoice.id]['amount_untaxed'] += line.price_subtotal + if line.free: + res[invoice.id]['amount_untaxed_free'] += ( + line.price_subtotal) + # costruiamo un dizionario chiave=iva e valore=imponibile + for tax in line.invoice_line_tax_id: + if tax.amount in lines: + lines[tax.amount] += line.price_subtotal + else: + lines[tax.amount] = line.price_subtotal + for tl in lines: + res[invoice.id]['amount_tax_free'] += lines[tl] * (1 + tl) + for line in invoice.tax_line: + res[invoice.id]['amount_tax'] += line.amount + res[invoice.id]['amount_total'] = ( + res[invoice.id]['amount_tax'] + + res[invoice.id]['amount_untaxed']) + return res + + def _get_invoice_line(self, cr, uid, ids, context=None): + result = {} + for line in self.pool['account.invoice.line'].browse(cr, uid, ids, + context=context): + result[line.invoice_id.id] = True + return result.keys() + + def _get_invoice_tax(self, cr, uid, ids, context=None): + result = {} + for tax in self.pool['account.invoice.tax'].browse(cr, uid, ids, + context=context): + result[tax.invoice_id.id] = True + return result.keys() + + _columns = { + 'amount_untaxed_free': fields.function( + _amount_all, digits_compute=dp.get_precision('Account'), + string='"For Free" Amount', + store={ + 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, + ['invoice_line'], 20), + 'account.invoice.tax': (_get_invoice_tax, None, 20), + 'account.invoice.line': (_get_invoice_line, [ + 'price_unit', 'invoice_line_tax_id', 'quantity', + 'discount', 'invoice_id'], 20), + }, + multi='all'), + 'amount_tax_free': fields.function( + _amount_all, digits_compute=dp.get_precision('Account'), + string='"For Free" Tax', + store={ + 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, + ['invoice_line'], 20), + 'account.invoice.tax': (_get_invoice_tax, None, 20), + 'account.invoice.line': (_get_invoice_line, [ + 'price_unit', 'invoice_line_tax_id', 'quantity', + 'discount', 'invoice_id'], 20), + }, + multi='all'), + 'amount_untaxed': fields.function( + _amount_all, digits_compute=dp.get_precision('Account'), + string='Untaxed', + store={ + 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, + ['invoice_line'], 20), + 'account.invoice.tax': (_get_invoice_tax, None, 20), + 'account.invoice.line': (_get_invoice_line, [ + 'price_unit', 'invoice_line_tax_id', 'quantity', + 'discount', 'invoice_id'], 20), + }, + multi='all'), + 'amount_tax': fields.function( + _amount_all, digits_compute=dp.get_precision('Account'), + string='Tax', + store={ + 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, + ['invoice_line'], 20), + 'account.invoice.tax': (_get_invoice_tax, None, 20), + 'account.invoice.line': (_get_invoice_line, [ + 'price_unit', 'invoice_line_tax_id', 'quantity', + 'discount', 'invoice_id'], 20), + }, + multi='all'), + 'amount_total': fields.function( + _amount_all, digits_compute=dp.get_precision('Account'), + string='Total', + store={ + 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, + ['invoice_line'], 20), + 'account.invoice.tax': (_get_invoice_tax, None, 20), + 'account.invoice.line': (_get_invoice_line, [ + 'price_unit', 'invoice_line_tax_id', 'quantity', + 'discount', 'invoice_id'], 20), + }, + multi='all'), + } + + def finalize_invoice_move_lines(self, cr, uid, invoice_browse, move_lines): + if invoice_browse.amount_untaxed_free > 0.0: + precision = self.pool['decimal.precision'].precision_get(cr, 1, + 'Account') + precision_diff = round( + invoice_browse.amount_tax_free - + invoice_browse.amount_untaxed_free, precision) + account_id = self.pool['account.invoice.line']._default_account_id( + cr, uid, {'type': 'out_invoice'}) + if (invoice_browse.amount_untaxed_free == + invoice_browse.amount_untaxed): + # se imponibile = imponibile omaggio + move_lines[-1][2]['account_id'] = account_id + move_lines[-1][2]['date_maturity'] = False + move_lines[-1][2]['debit'] -= invoice_browse.amount_tax_free + + # riga imponibile omaggio + new_line = { + 'analytic_account_id': False, + 'tax_code_id': False, + 'analytic_lines': [], + 'tax_amount': False, + 'name': _('"For Free" Amount'), + 'ref': '', + 'analytics_id': False, + 'currency_id': False, + 'debit': invoice_browse.amount_untaxed_free, + 'product_id': False, + 'date_maturity': False, + 'credit': False, + 'date': move_lines[0][2]['date'], + 'amount_currency': 0, + 'product_uom_id': False, + 'quantity': 1, + 'partner_id': move_lines[0][2]['partner_id'], + 'account_id': account_id, + } + move_lines += [(0, 0, new_line)] + # riga iva omaggio + new_line = { + 'analytic_account_id': False, + 'tax_code_id': False, + 'analytic_lines': [], + 'tax_amount': False, + 'name': _('"For Free" Tax Amount'), + 'ref': '', + 'analytics_id': False, + 'currency_id': False, + 'debit': precision_diff, + 'product_id': False, + 'date_maturity': False, + 'credit': False, + 'date': move_lines[0][2]['date'], + 'amount_currency': 0, + 'product_uom_id': False, + 'quantity': 1, + 'partner_id': move_lines[0][2]['partner_id'], + 'account_id': account_id, + } + move_lines += [(0, 0, new_line)] + return move_lines + +account_invoice() === added file 'free_invoice_line/account/account_view.xml' --- free_invoice_line/account/account_view.xml 1970-01-01 00:00:00 +0000 +++ free_invoice_line/account/account_view.xml 2014-09-04 08:53:08 +0000 @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data> + + <record id="free_invoice_line_form" model="ir.ui.view"> + <field name="name">account.invoice.form</field> + <field name="model">account.invoice</field> + <field name="inherit_id" ref="account.invoice_form"/> + <field name="arch" type="xml"> + <field name="discount" position="after"> + <field name="free" /> + </field> + </field> + </record> + + </data> +</openerp> === added directory 'free_invoice_line/i18n' === added file 'free_invoice_line/i18n/free_invoice_line.pot' --- free_invoice_line/i18n/free_invoice_line.pot 1970-01-01 00:00:00 +0000 +++ free_invoice_line/i18n/free_invoice_line.pot 2014-09-04 08:53:08 +0000 @@ -0,0 +1,54 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * free_invoice_line +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-09-04 08:44+0000\n" +"PO-Revision-Date: 2014-09-04 08:44+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: free_invoice_line +#: field:account.invoice,amount_untaxed_free:0 +#: code:addons/free_invoice_line/account/account.py:171 +#, python-format +msgid "\"For Free\" Amount" +msgstr "" + +#. module: free_invoice_line +#: field:account.invoice,amount_tax_free:0 +msgid "\"For Free\" Tax" +msgstr "" + +#. module: free_invoice_line +#: code:addons/free_invoice_line/account/account.py:193 +#, python-format +msgid "\"For Free\" Tax Amount" +msgstr "" + +#. module: free_invoice_line +#: field:account.invoice.line,free:0 +msgid "For Free" +msgstr "" + +#. module: free_invoice_line +#: code:_description:0 +#: model:ir.model,name:free_invoice_line.model_account_invoice +#, python-format +msgid "Invoice" +msgstr "" + +#. module: free_invoice_line +#: code:_description:0 +#: model:ir.model,name:free_invoice_line.model_account_invoice_line +#, python-format +msgid "Invoice Line" +msgstr "" + === added file 'free_invoice_line/i18n/it.po' --- free_invoice_line/i18n/it.po 1970-01-01 00:00:00 +0000 +++ free_invoice_line/i18n/it.po 2014-09-04 08:53:08 +0000 @@ -0,0 +1,54 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * free_invoice_line +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-09-04 08:44+0000\n" +"PO-Revision-Date: 2014-09-04 08:44+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: free_invoice_line +#: field:account.invoice,amount_untaxed_free:0 +#: code:addons/free_invoice_line/account/account.py:171 +#, python-format +msgid "\"For Free\" Amount" +msgstr "Imponibile Omaggio" + +#. module: free_invoice_line +#: field:account.invoice,amount_tax_free:0 +msgid "\"For Free\" Tax" +msgstr "Imposte Omaggio" + +#. module: free_invoice_line +#: code:addons/free_invoice_line/account/account.py:193 +#, python-format +msgid "\"For Free\" Tax Amount" +msgstr "Importo imposte omaggio" + +#. module: free_invoice_line +#: field:account.invoice.line,free:0 +msgid "For Free" +msgstr "Omaggio" + +#. module: free_invoice_line +#: code:_description:0 +#: model:ir.model,name:free_invoice_line.model_account_invoice +#, python-format +msgid "Invoice" +msgstr "Fattura" + +#. module: free_invoice_line +#: code:_description:0 +#: model:ir.model,name:free_invoice_line.model_account_invoice_line +#, python-format +msgid "Invoice Line" +msgstr "Righe Fattura" +
-- Mailing list: https://launchpad.net/~openerp-community-reviewer Post to : [email protected] Unsubscribe : https://launchpad.net/~openerp-community-reviewer More help : https://help.launchpad.net/ListHelp

