mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[ADD] account_invoice_currency: Migrated to 8.0 with new API
This commit is contained in:
@@ -1,173 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2004-2011
|
||||
# Pexego Sistemas Informáticos. (http://pexego.es) All Rights Reserved
|
||||
# Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
|
||||
#
|
||||
# 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
|
||||
from openerp.osv import orm
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class account_invoice(orm.Model):
|
||||
"""
|
||||
Inheritance of account invoice to add company currency amounts
|
||||
"""
|
||||
|
||||
_inherit = "account.invoice"
|
||||
|
||||
def _get_invoice_line2(self, cr, uid, ids, context=None):
|
||||
result = {}
|
||||
for line in self.pool.get('account.invoice.line').browse(
|
||||
cr, uid, ids, context=context):
|
||||
result[line.invoice_id.id] = True
|
||||
return result.keys()
|
||||
|
||||
def _get_invoice_tax2(self, cr, uid, ids, context=None):
|
||||
result = {}
|
||||
for tax in self.pool.get('account.invoice.tax').browse(
|
||||
cr, uid, ids, context=context):
|
||||
result[tax.invoice_id.id] = True
|
||||
return result.keys()
|
||||
|
||||
def _cc_amount_all(self, cr, uid, ids, name, args, context=None):
|
||||
res = {}
|
||||
for invoice in self.browse(cr, uid, ids, context=context):
|
||||
if invoice.company_id.currency_id == invoice.currency_id:
|
||||
res[invoice.id] = {
|
||||
'cc_amount_untaxed': invoice.amount_untaxed,
|
||||
'cc_amount_tax': invoice.amount_tax,
|
||||
'cc_amount_total': invoice.amount_total,
|
||||
}
|
||||
else:
|
||||
res[invoice.id] = {
|
||||
'cc_amount_untaxed': 0.0,
|
||||
'cc_amount_tax': 0.0,
|
||||
'cc_amount_total': 0.0,
|
||||
}
|
||||
|
||||
# It could be computed only in open or paid invoices with a
|
||||
# generated account move
|
||||
if invoice.move_id:
|
||||
# Accounts to compute amount_untaxed
|
||||
line_account = []
|
||||
for line in invoice.invoice_line:
|
||||
if line.account_id.id not in line_account:
|
||||
line_account.append(line.account_id.id)
|
||||
|
||||
# Accounts to compute amount_tax
|
||||
tax_account = []
|
||||
for line in invoice.tax_line:
|
||||
if (line.account_id.id not in tax_account and
|
||||
line.amount != 0):
|
||||
tax_account.append(line.account_id.id)
|
||||
|
||||
# The company currency amounts are the debit-credit
|
||||
# amounts in the account moves
|
||||
for line in invoice.move_id.line_id:
|
||||
if line.account_id.id in line_account:
|
||||
amt = line.debit - line.credit
|
||||
res[invoice.id]['cc_amount_untaxed'] += amt
|
||||
if line.account_id.id in tax_account:
|
||||
amt = line.debit - line.credit
|
||||
res[invoice.id]['cc_amount_tax'] += amt
|
||||
if invoice.type in ('out_invoice', 'in_refund'):
|
||||
res[invoice.id]['cc_amount_untaxed'] = \
|
||||
-res[invoice.id]['cc_amount_untaxed']
|
||||
res[invoice.id]['cc_amount_tax'] = \
|
||||
-res[invoice.id]['cc_amount_tax']
|
||||
res[invoice.id]['cc_amount_total'] = (
|
||||
res[invoice.id]['cc_amount_tax'] +
|
||||
res[invoice.id]['cc_amount_untaxed']
|
||||
)
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'cc_amount_untaxed': fields.function(
|
||||
_cc_amount_all,
|
||||
method=True,
|
||||
digits_compute=dp.get_precision('Account'),
|
||||
string='Company Cur. Untaxed',
|
||||
help="Invoice untaxed amount in the company currency"
|
||||
"(useful when invoice currency is different "
|
||||
"from company currency).",
|
||||
store={
|
||||
'account.invoice': (lambda self, cr, uid, ids, c={}: ids,
|
||||
['invoice_line',
|
||||
'currency_id',
|
||||
'move_id'],
|
||||
20),
|
||||
'account.invoice.tax': (_get_invoice_tax2, None, 20),
|
||||
'account.invoice.line': (_get_invoice_line2,
|
||||
['price_unit',
|
||||
'invoice_line_tax_id',
|
||||
'quantity', 'discount'],
|
||||
20),
|
||||
},
|
||||
multi='cc_all'
|
||||
),
|
||||
|
||||
'cc_amount_tax': fields.function(
|
||||
_cc_amount_all,
|
||||
method=True,
|
||||
digits_compute=dp.get_precision('Account'),
|
||||
string='Company Cur. Tax',
|
||||
help="Invoice tax amount in the company currency "
|
||||
"(useful when invoice currency is different "
|
||||
"from company currency).",
|
||||
store={
|
||||
'account.invoice': (lambda self, cr, uid, ids, c={}: ids,
|
||||
['invoice_line',
|
||||
'currency_id',
|
||||
'move_id'],
|
||||
20),
|
||||
'account.invoice.tax': (_get_invoice_tax2, None, 20),
|
||||
'account.invoice.line': (_get_invoice_line2,
|
||||
['price_unit',
|
||||
'invoice_line_tax_id',
|
||||
'quantity', 'discount'],
|
||||
20),
|
||||
},
|
||||
multi='cc_all'
|
||||
),
|
||||
|
||||
'cc_amount_total': fields.function(
|
||||
_cc_amount_all,
|
||||
method=True,
|
||||
digits_compute=dp.get_precision('Account'),
|
||||
string='Company Cur. Total',
|
||||
help="Invoice total amount in the company currency "
|
||||
"(useful when invoice currency is different from "
|
||||
"company currency).",
|
||||
store={
|
||||
'account.invoice': (lambda self, cr, uid, ids, c={}: ids,
|
||||
['invoice_line',
|
||||
'currency_id',
|
||||
'move_id'],
|
||||
20),
|
||||
'account.invoice.tax': (_get_invoice_tax2, None, 20),
|
||||
'account.invoice.line': (_get_invoice_line2,
|
||||
['price_unit',
|
||||
'invoice_line_tax_id',
|
||||
'quantity', 'discount'],
|
||||
20),
|
||||
},
|
||||
multi='cc_all'),
|
||||
}
|
||||
30
account_invoice_currency/README.rst
Normal file
30
account_invoice_currency/README.rst
Normal file
@@ -0,0 +1,30 @@
|
||||
Account invoices in company currency
|
||||
====================================
|
||||
|
||||
This module adds functional fields to show invoices in the company currency:
|
||||
amount untaxed, amount taxed and amount total.
|
||||
|
||||
These fields are shown in "Other information" tab in invoice form.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Jordi Esteve <jesteve@zikzakmedia.com>
|
||||
* Joaquín Gutierrez <joaquing.pedrosa@gmail.com>
|
||||
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
.. image:: http://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: http://odoo-community.org
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
|
||||
|
||||
To contribute to this module, please visit http://odoo-community.org.
|
||||
@@ -2,7 +2,6 @@
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2004-2011 Zikzakmedia S.L. (http://zikzakmedia.com)
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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
|
||||
@@ -18,4 +17,4 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from . import invoice
|
||||
from . import models
|
||||
@@ -5,6 +5,7 @@
|
||||
# Copyright (C) 2004-2011 Zikzakmedia S.L. (http://zikzakmedia.com)
|
||||
# Jordi Esteve <jesteve@zikzakmedia.com>
|
||||
# Copyright (c) 2013 Joaquin Gutierrez (http://www.gutierrezweb.es)
|
||||
# Copyright (c) 2014-2015 Serv. Tecnol. Avanzados - Pedro M. Baeza
|
||||
#
|
||||
# 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
|
||||
@@ -24,23 +25,17 @@
|
||||
{
|
||||
'name': "Company currency in invoices",
|
||||
'version': "1.0",
|
||||
'author': "Zikzakmedia SL",
|
||||
'website': "http://www.zikzakmedia.com",
|
||||
'author': "Zikzakmedia SL, "
|
||||
"Joaquín Gutierrez, "
|
||||
"Serv. Tecnol. Avanzados - Pedro M. Baeza",
|
||||
'website': "http://www.zikzakmedia.com, "
|
||||
"http://www.gutierrezweb.es, "
|
||||
"http://www.serviciosbaeza.com",
|
||||
'category': "Localisation / Accounting",
|
||||
'contributors': ['Joaquín Gutierrez'],
|
||||
"description": """
|
||||
This Module adds functional fields to show invoice in the company currency
|
||||
==========================================================================
|
||||
|
||||
Amount Untaxed, Amount Tax and Amount Total invoice
|
||||
fields in the company currency.
|
||||
These fields are shown in "Other information" tab in invoice form.
|
||||
""",
|
||||
'license': "AGPL-3",
|
||||
'depends': ["account"],
|
||||
'data': [
|
||||
"account_invoice_view.xml"
|
||||
"views/account_invoice_view.xml"
|
||||
],
|
||||
'installable': False,
|
||||
'active': False,
|
||||
'installable': True,
|
||||
}
|
||||
@@ -57,7 +57,7 @@ msgstr ""
|
||||
#. module: account_invoice_currency
|
||||
#: view:account.invoice:0
|
||||
msgid "Amounts in company currency"
|
||||
msgstr "Importes moneda empresa"
|
||||
msgstr "Importes moneda compañía"
|
||||
|
||||
#. module: account_invoice_currency
|
||||
#: model:ir.model,name:account_invoice_currency.model_account_invoice
|
||||
20
account_invoice_currency/models/__init__.py
Normal file
20
account_invoice_currency/models/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2004-2011 Zikzakmedia S.L. (http://zikzakmedia.com)
|
||||
#
|
||||
# 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_invoice
|
||||
77
account_invoice_currency/models/account_invoice.py
Normal file
77
account_invoice_currency/models/account_invoice.py
Normal file
@@ -0,0 +1,77 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2004-2011
|
||||
# Pexego Sistemas Informáticos. (http://pexego.es)
|
||||
# Zikzakmedia S.L. (http://zikzakmedia.com)
|
||||
#
|
||||
# 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 import models, fields, api
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = "account.invoice"
|
||||
|
||||
@api.one
|
||||
@api.depends('amount_total', 'amount_untaxed', 'amount_tax',
|
||||
'currency_id', 'move_id')
|
||||
def _cc_amount_all(self):
|
||||
if self.company_id.currency_id == self.currency_id:
|
||||
self.cc_amount_untaxed = self.amount_untaxed
|
||||
self.cc_amount_tax = self.amount_tax
|
||||
self.cc_amount_total = self.amount_total
|
||||
else:
|
||||
self.cc_amount_untaxed = 0.0
|
||||
self.cc_amount_tax = 0.0
|
||||
self.cc_amount_total = 0.0
|
||||
# It could be computed only in open or paid invoices with a
|
||||
# generated account move
|
||||
if self.move_id:
|
||||
# Accounts to compute amount_untaxed
|
||||
line_accounts = set([x.account_id.id for x in
|
||||
self.invoice_line])
|
||||
# Accounts to compute amount_tax
|
||||
tax_accounts = set([x.account_id.id for x in
|
||||
self.tax_line if x.amount != 0])
|
||||
# The company currency amounts are the debit-credit
|
||||
# amounts in the account moves
|
||||
for line in self.move_id.line_id:
|
||||
if line.account_id.id in line_accounts:
|
||||
self.cc_amount_untaxed += line.debit - line.credit
|
||||
if line.account_id.id in tax_accounts:
|
||||
self.cc_amount_tax += line.debit - line.credit
|
||||
if self.type in ('out_invoice', 'in_refund'):
|
||||
self.cc_amount_untaxed = -self.cc_amount_untaxed
|
||||
self.cc_amount_tax = -self.cc_amount_tax
|
||||
self.cc_amount_total = (self.cc_amount_tax +
|
||||
self.cc_amount_untaxed)
|
||||
|
||||
cc_amount_untaxed = fields.Float(
|
||||
compute="_cc_amount_all", digits_compute=dp.get_precision('Account'),
|
||||
string='Company Cur. Untaxed',
|
||||
help="Invoice untaxed amount in the company currency (useful when "
|
||||
"invoice currency is different from company currency).")
|
||||
cc_amount_tax = fields.Float(
|
||||
compute="_cc_amount_all", digits_compute=dp.get_precision('Account'),
|
||||
string='Company Cur. Tax',
|
||||
help="Invoice tax amount in the company currency (useful when invoice "
|
||||
"currency is different from company currency).")
|
||||
cc_amount_total = fields.Float(
|
||||
compute="_cc_amount_all", digits_compute=dp.get_precision('Account'),
|
||||
string='Company Cur. Total',
|
||||
help="Invoice total amount in the company currency (useful when "
|
||||
"invoice currency is different from company currency).")
|
||||
Reference in New Issue
Block a user