Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10.0 Port invoice_fiscal_position_update #191

Merged
merged 5 commits into from
Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions account_invoice_fiscal_position_update/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

==============================
Invoice Fiscal Position Update
==============================

With this module, when a user changes the fiscal position of an invoice, the
taxes and the accounts on all the invoice lines which have a product are
automatically updated. The invoice lines without a product are not updated and
a warning is displayed to the user in this case.

Configuration
=============

No specific configuration needed. This module uses the standard
configuration of the fiscal positions.

Usage
=====

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/95/10.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/account-invoicing/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======

Contributors
------------

* Mathieu Vatel (Julius Network Solutions)
* Alexis de Lattre <alexis.delattre@akretion.com>
* Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://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 https://odoo-community.org.
3 changes: 3 additions & 0 deletions account_invoice_fiscal_position_update/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
19 changes: 19 additions & 0 deletions account_invoice_fiscal_position_update/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# © 2011-2014 Julius Network Solutions SARL <contact@julius.fr>
# © 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


{
'name': 'Invoice Fiscal Position Update',
'version': '10.0.1.0.0',
'category': 'Accounting & Finance',
'license': 'AGPL-3',
'summary': 'Changing the fiscal position of an invoice will auto-update '
'invoice lines',
'author': "Julius Network Solutions,"
"Akretion,"
"Odoo Community Association (OCA)",
'depends': ['account'],
'installable': True,
}
3 changes: 3 additions & 0 deletions account_invoice_fiscal_position_update/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import account_invoice
Original file line number Diff line number Diff line change
@@ -1,67 +1,56 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Invoice Fiscal Position Update module for OpenERP
# Copyright (C) 2011-2014 Julius Network Solutions SARL <contact@julius.fr>
# Copyright (C) 2014 Akretion (http://www.akretion.com)
# @author Mathieu Vatel <mathieu _at_ julius.fr>
# @author Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
# © 2011-2014 Julius Network Solutions SARL <contact@julius.fr>
# © 2014 Akretion (http://www.akretion.com)
# @author Mathieu Vatel <mathieu _at_ julius.fr>
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api, _

from odoo import models, api, _

class account_invoice(models.Model):

class AccountInvoice(models.Model):
_inherit = "account.invoice"

@api.onchange('fiscal_position')
@api.onchange('fiscal_position_id')
def fiscal_position_change(self):
"""Updates taxes and accounts on all invoice lines"""
self.ensure_one()
res = {}
lines_without_product = []
fp = self.fiscal_position
fp = self.fiscal_position_id
inv_type = self.type
for line in self.invoice_line:
for line in self.invoice_line_ids:
if line.product_id:
product = line.product_id
if inv_type in ('out_invoice', 'out_refund'):
account = (
product.property_account_income or
product.categ_id.property_account_income_categ)
taxes = product.taxes_id
product.property_account_income_id or
product.categ_id.property_account_income_categ_id)
# M2M fields don't have an option 'company_dependent=True'
# so we need per-company post-filtering
taxes = product.taxes_id.filtered(
lambda tax: tax.company_id == self.company_id)
else:
account = (
product.property_account_expense or
product.categ_id.property_account_expense_categ)
taxes = product.supplier_taxes_id
taxes = taxes or account.tax_ids
product.property_account_expense_id or
product.categ_id.property_account_expense_categ_id)
taxes = product.supplier_taxes_id.filtered(
lambda tax: tax.company_id == self.company_id)
taxes = taxes or account.tax_ids.filtered(
lambda tax: tax.company_id == self.company_id)
if fp:
account = fp.map_account(account)
taxes = fp.map_tax(taxes)

line.invoice_line_tax_id = [(6, 0, taxes.ids)]
line.invoice_line_tax_ids = [(6, 0, taxes.ids)]
line.account_id = account.id
else:
lines_without_product.append(line.name)

if lines_without_product:
res['warning'] = {'title': _('Warning')}
if len(lines_without_product) == len(self.invoice_line):
if len(lines_without_product) == len(self.invoice_line_ids):
res['warning']['message'] = _(
"The invoice lines were not updated to the new "
"Fiscal Position because they don't have products.\n"
Expand Down
3 changes: 3 additions & 0 deletions account_invoice_fiscal_position_update/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import test_inv_fiscal_pos_update
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# -*- coding: utf-8 -*-
# © 2014 ToDay Akretion (http://www.akretion.com)
# @author Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.addons.account.tests.account_test_classes import AccountingTestCase
import time


class TestProductIdChange(AccountingTestCase):
"""Test that when an included tax is mapped by a fiscal position,
when position fiscal change taxes and account wil be update on
invoice lines.
"""

def setUp(self):
super(TestProductIdChange, self).setUp()
self.invoice_model = self.env['account.invoice']
self.fiscal_position_model = self.env['account.fiscal.position']
self.fiscal_position_tax_model = \
self.env['account.fiscal.position.tax']
self.fiscal_position_account_model = \
self.env['account.fiscal.position.account']
self.tax_model = self.env['account.tax']
self.account_model = self.env['account.account']
self.pricelist_model = self.env['product.pricelist']
self.res_partner_model = self.env['res.partner']
self.product_tmpl_model = self.env['product.template']
self.product_model = self.env['product.product']
self.invoice_line_model = self.env['account.invoice.line']
self.account_user_type = self.env.ref(
'account.data_account_type_revenue')
self.account_receivable = self.env['account.account'].search(
[('user_type_id', '=',
self.env.ref('account.data_account_type_receivable').id)],
limit=1)
self.account_revenue = self.env['account.account'].search(
[('user_type_id', '=',
self.account_user_type.id)],
limit=1)

def test_fiscal_position_id_change(self):
partner = self.res_partner_model.create(dict(name="George"))
account_export_id = self.account_model.sudo().create({
'code': "710000",
'name': "customer export account",
'user_type_id': self.account_user_type.id,
'reconcile': True,
})
tax_sale = self.tax_model.create({
'name': 'Sale tax',
'type_tax_use': 'sale',
'amount': '20.00',
})

tax_export_sale = self.tax_model.create({
'name': "Export tax",
'type_tax_use': 'sale',
'amount': '0.00'
})

product_tmpl = self.product_tmpl_model.create({
'name': 'Car',
'lst_price': '15000',
'taxes_id': [(6, 0, [tax_sale.id])],
'property_account_income_id': self.account_revenue.id,

})
product = self.product_model.create({
'product_tmpl_id': product_tmpl.id,
'standard_price': '12000',
})
fp = self.fiscal_position_model.create({
'name': "fiscal position export", 'sequence': 1,
})

fp_tax_sale = self.fiscal_position_tax_model.create({
'position_id': fp.id,
'tax_src_id': tax_sale.id,
'tax_dest_id': tax_export_sale.id,
})

fp_account = self.fiscal_position_account_model.create({
'position_id': fp.id,
'account_src_id': self.account_revenue.id,
'account_dest_id': account_export_id.id,
})

out_invoice = self.invoice_model.create({
'partner_id': partner.id,
'reference_type': 'none',
'name': 'invoice to client',
'account_id': self.account_receivable.id,
'type': 'out_invoice',
'date_invoice': time.strftime('%Y') + '-04-01',
})
out_line = self.invoice_line_model.create({
'product_id': product.id,
'price_unit': 15000,
'quantity': 1,
'invoice_id': out_invoice.id,
'name': 'Car',
'account_id': self.account_revenue.id,

})

out_line._onchange_product_id()
self.assertEquals(
out_line.invoice_line_tax_ids[0],
tax_sale,
"The sale tax off invoice line must be the same of product")
out_invoice.fiscal_position_id = fp
out_invoice.fiscal_position_change()
self.assertEquals(
out_line.invoice_line_tax_ids[0],
fp_tax_sale.tax_dest_id,
'The sale tax of invoice line must be changed by'
' fiscal position')
self.assertEquals(
out_line.account_id,
fp_account.account_dest_id,
'The account revenu of invoice line must be changed by'
' fiscal position')
23 changes: 0 additions & 23 deletions invoice_fiscal_position_update/__init__.py

This file was deleted.

45 changes: 0 additions & 45 deletions invoice_fiscal_position_update/__manifest__.py

This file was deleted.

Loading