[11.0][MIG] account_fiscal_position_vat_check: Migration to 11.0

This commit is contained in:
Raf Ven
2018-08-17 09:13:58 +02:00
parent 140557fa96
commit 2008228129
8 changed files with 171 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
=================================
@@ -44,10 +44,18 @@ help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
Contributors
------------
* Alexis de Lattre <alexis.delattre@akretion.com>
* Raf Ven <raf.ven@dynapps.be> (https://odoo.dynapps.be)
Do not contact contributors directly about support or help with technical issues.
Maintainer
----------

View File

@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
from . import models

View File

@@ -1,18 +1,22 @@
# -*- coding: utf-8 -*-
# © 2013-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# © 2018 DynApps (Raf Ven <raf.ven@dynapps.be>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Account Fiscal Position VAT Check',
'version': '10.0.1.0.0',
'category': 'Accounting & Finance',
'license': 'AGPL-3',
'summary': 'Check VAT on invoice validation',
'author': "Akretion,Odoo Community Association (OCA)",
'website': 'http://www.akretion.com',
'depends': ['account', 'base_vat'],
'data': [
'views/account_fiscal_position.xml',
"name": "Account Fiscal Position VAT Check",
"version": "11.0.1.0.0",
"category": "Accounting & Finance",
"license": "AGPL-3",
"summary": "Check VAT on invoice validation",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "http://www.akretion.com",
"depends": [
"account",
"base_vat"
],
'installable': True,
"data": [
"views/account_fiscal_position.xml",
],
"installable": True,
"application": False,
}

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from . import account_invoice
from . import partner

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2013-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2013-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@@ -9,17 +8,18 @@ class ResPartner(models.Model):
_inherit = 'res.partner'
@api.onchange('property_account_position_id')
def fiscal_position_change(self):
def onchange_fiscal_position(self):
"""Warning if the fiscal position requires a VAT number and the
partner doesn't have one yet"""
fp = self.property_account_position_id
if fp.vat_required and self.customer and not self.vat:
fiscal_position = self.property_account_position_id
if fiscal_position.vat_required and self.customer and not self.vat:
return {
'warning': {
'title': _('Missing VAT number:'),
'message': _(
"You have set the fiscal position '%s' "
"that require the customer to have a VAT number, "
"but the VAT number is missing.") % fp.name
"but the VAT number is missing."
) % fiscal_position.name
}
}

View File

@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_fiscal_position_vat_check

View File

@@ -0,0 +1,137 @@
# Copyright 2018 Raf Ven <raf.ven@dynapps.be>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError
class TestFiscalPositionVatCheck(TransactionCase):
# pylint: disable=too-many-instance-attributes
def setUp(self):
super(TestFiscalPositionVatCheck, self).setUp()
self._create_fiscal_positions()
self._create_partners()
self._configure_accounting()
def _create_fiscal_positions(self):
self.fp_b2c = self.env['account.fiscal.position'].create(dict(
name="EU-VAT-B2C",
vat_required=False,
))
self.fp_b2b = self.env['account.fiscal.position'].create(dict(
name="EU-VAT-B2B",
vat_required=True,
))
def _create_partners(self):
self.partner_b2c = self.env['res.partner'].create(dict(
name="Test Partner B2C",
))
self.partner_b2b = self.env['res.partner'].create(dict(
name="Test Partner B2B",
vat="BE0477472701",
))
def _configure_accounting(self):
self.product = self.env['product.product'].create(dict(
name='product name',
))
self.account_type1 = self.env['account.account.type'].create(dict(
name='acc type test 1',
type='receivable',
))
self.account_type2 = self.env['account.account.type'].create(dict(
name='acc type test 2',
type='other',
))
self.account_account = self.env['account.account'].create(dict(
name='acc test',
code='X2020',
user_type_id=self.account_type1.id,
reconcile=True,
))
self.account_account_line = self.env['account.account'].create(dict(
name='acc inv line test',
code='X2021',
user_type_id=self.account_type2.id,
reconcile=True,
))
self.sale_sequence = self.env['ir.sequence'].create(dict(
name='Journal Sale',
prefix='SALE',
padding=6,
company_id=self.env.ref("base.main_company").id,
))
self.account_journal_sale = self.env['account.journal'].create(dict(
name='Sale journal',
code='SALE',
type='sale',
sequence_id=self.sale_sequence.id
))
def create_out_invoice(self, partner):
invoice = self.env['account.invoice'].create(dict(
partner_id=partner.id,
account_id=self.account_account.id,
type='out_invoice',
journal_id=self.account_journal_sale.id,
))
self.env['account.invoice.line'].create(dict(
product_id=self.product.id,
quantity=1.0,
price_unit=100.0,
invoice_id=invoice.id,
name='product that cost 100',
account_id=self.account_account_line.id,
))
return invoice
def test_fiscal_position_vat_check(self):
# Empty fiscal position should not return a warning
result = self.partner_b2c.onchange_fiscal_position()
self.assertEqual(result, None)
# B2C fiscal position should not return a warning
self.partner_b2c.property_account_position_id = self.fp_b2c
result = self.partner_b2c.onchange_fiscal_position()
self.assertEqual(result, None)
# B2B fiscal position should return a warning
self.partner_b2c.property_account_position_id = self.fp_b2b
result = self.partner_b2c.onchange_fiscal_position()
self.assertEqual(result['warning']['title'], 'Missing VAT number:')
# Create Invoice for B2C partner with B2C fiscal position
self.partner_b2c.property_account_position_id = self.fp_b2c
invoice = self.create_out_invoice(partner=self.partner_b2c)
invoice.action_invoice_open()
# Create Invoice for B2C partner with B2B fiscal position
self.partner_b2c.property_account_position_id = self.fp_b2b
invoice = self.create_out_invoice(partner=self.partner_b2c)
err_msg = "But the Customer '.*' doesn't have a VAT number"
with self.assertRaisesRegex(UserError, err_msg):
invoice.action_invoice_open()
# Empty fiscal position should not return a warning
result = self.partner_b2b.onchange_fiscal_position()
self.assertEqual(result, None)
# B2C fiscal position should not return a warning
self.partner_b2b.property_account_position_id = self.fp_b2c
result = self.partner_b2b.onchange_fiscal_position()
self.assertEqual(result, None)
# B2B fiscal position should return a warning
self.partner_b2b.property_account_position_id = self.fp_b2b
result = self.partner_b2b.onchange_fiscal_position()
self.assertEqual(result, None)
# Create Invoice for B2B partner with B2B fiscal position
self.partner_b2b.property_account_position_id = self.fp_b2b
invoice = self.create_out_invoice(partner=self.partner_b2b)
invoice.action_invoice_open()
# Create Invoice for B2B partner with B2C fiscal position
self.partner_b2b.property_account_position_id = self.fp_b2c
invoice = self.create_out_invoice(partner=self.partner_b2b)
invoice.action_invoice_open()