-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png | ||
:target: https://www.gnu.org/licenses/agpl | ||
:alt: License: AGPL-3 | ||
|
||
=============================== | ||
Romania - Partner Create by VAT | ||
=============================== | ||
|
||
This module allows you to create the partners (companies) based on their | ||
VAT number. It will complete the name, address of the partner from ANAF | ||
webservice. | ||
|
||
ANAF | ||
https://webservicesp.anaf.ro/PlatitorTvaRest/api/v2/ | ||
|
||
Installation | ||
============ | ||
|
||
To install this module, you need to: | ||
|
||
* clone the branch 11.0 of the repository https://github.com/OCA/l10n-romania | ||
* add the path to this repository in your configuration (addons-path) | ||
* update the module list | ||
* search for "Romania - Partner Create by VAT" in your addons | ||
* install the module | ||
|
||
Usage | ||
===== | ||
|
||
Put the VAT number in the partner's form and save the new record | ||
|
||
* If it'a a romanian company, the first source used is the ANAF. | ||
* If it's not a romanian company, will use the datas from VIES Webservice if they are available. | ||
|
||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/177/11.0 | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-romania/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smash it by providing detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Fekete Mihai <feketemihai@gmail.com> | ||
* Dorin Hongu <dhongu@gmail.com> | ||
* Adrian Vasile <adrian.vasile@gmail.com> | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2015 Forest and Biomass Romania | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import models, tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2015 Forest and Biomass Romania | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
'name': 'Romania - Partner Create by VAT', | ||
'summary': 'Romania - Partner Create by VAT', | ||
'version': '11.0.1.0.0', | ||
'category': 'Localization', | ||
'author': 'Forest and Biomass Romania, ' | ||
'Odoo Community Association (OCA)', | ||
'website': 'https://www.forbiom.eu', | ||
'license': 'AGPL-3', | ||
'application': False, | ||
'installable': True, | ||
'depends': ['l10n_ro', 'base_vat_autocomplete'], | ||
'data': ['views/res_partner_view.xml'], | ||
'images': [], | ||
'auto_install': False, | ||
} |
28 changes: 28 additions & 0 deletions
28
l10n_ro_partner_create_by_vat/i18n/l10n_ro_partner_create_by_vat.pot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * l10n_ro_partner_create_by_vat | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2017-10-19 11:55+0000\n" | ||
"PO-Revision-Date: 2017-10-19 11:55+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: l10n_ro_partner_create_by_vat | ||
#: model:ir.model,name:l10n_ro_partner_create_by_vat.model_res_partner | ||
msgid "Contact" | ||
msgstr "" | ||
|
||
#. module: l10n_ro_partner_create_by_vat | ||
#: model:ir.model.fields,field_description:l10n_ro_partner_create_by_vat.field_res_partner_vat_subjected | ||
#: model:ir.model.fields,field_description:l10n_ro_partner_create_by_vat.field_res_users_vat_subjected | ||
msgid "VAT Legal Statement" | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * l10n_ro_partner_create_by_vat | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2017-10-19 11:55+0000\n" | ||
"PO-Revision-Date: 2017-10-19 11:55+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: l10n_ro_partner_create_by_vat | ||
#: model:ir.model,name:l10n_ro_partner_create_by_vat.model_res_partner | ||
msgid "Contact" | ||
msgstr "Contact" | ||
|
||
#. module: l10n_ro_partner_create_by_vat | ||
#: model:ir.model.fields,field_description:l10n_ro_partner_create_by_vat.field_res_partner_vat_subjected | ||
#: model:ir.model.fields,field_description:l10n_ro_partner_create_by_vat.field_res_users_vat_subjected | ||
msgid "VAT Legal Statement" | ||
msgstr "Platitor de TVA" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2015 Forest and Biomass Romania | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Copyright 2015 Forest and Biomass Romania | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import logging | ||
import requests | ||
|
||
from odoo import api, fields, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
CEDILLATRANS = bytes.maketrans(u'\u015f\u0163\u015e\u0162'.encode( | ||
'utf8'), u'\u0219\u021b\u0218\u021a'.encode('utf8')) | ||
|
||
headers = { | ||
"User-Agent": "Mozilla/5.0 (compatible; MSIE 7.01; Windows NT 5.0)", | ||
"Content-Type": "application/json;" | ||
} | ||
|
||
ANAF_URL = 'https://webservicesp.anaf.ro/PlatitorTvaRest/api/v2/ws/tva' | ||
|
||
|
||
class ResPartner(models.Model): | ||
_name = 'res.partner' | ||
_inherit = 'res.partner' | ||
|
||
vat_subjected = fields.Boolean('VAT Legal Statement') | ||
|
||
@api.model | ||
def _get_Anaf(self, cod): | ||
res = requests.post( | ||
ANAF_URL, | ||
json=[{'cui': cod, 'data': fields.Date.today()}], | ||
headers=headers) | ||
if res.status_code == 200: | ||
res = res.json() | ||
if res['found'] and res['found'][0]: | ||
result = res['found'][0] | ||
if result['data_sfarsit_ScpTVA'] and \ | ||
result['data_sfarsit_ScpTVA'] != ' ': | ||
res = requests.post( | ||
ANAF_URL, | ||
json=[{'cui': cod, 'data': result['data_sfarsit_ScpTVA']}], | ||
headers=headers) | ||
if res.status_code == 200: | ||
res = res.json() | ||
if res['found'] and res['found'][0]: | ||
result = res['found'][0] | ||
# Check if the partner was deactived | ||
if res['notfound'] and res['notfound'][0]: | ||
result = res['notfound'][0] | ||
if result['data_sfarsit_ScpTVA'] and \ | ||
result['data_sfarsit_ScpTVA'] != ' ': | ||
res = requests.post( | ||
ANAF_URL, | ||
json=[{'cui': cod, 'data': result['data_sfarsit_ScpTVA']}], | ||
headers=headers) | ||
if res.status_code == 200: | ||
res = res.json() | ||
if res['found'] and res['found'][0]: | ||
result = res['found'][0] | ||
if res['notfound'] and res['notfound'][0]: | ||
result = res['notfound'][0] | ||
return result | ||
|
||
@api.model | ||
def _Anaf_to_Odoo(self, result): | ||
res = {'name': result['denumire'].upper(), | ||
'vat_subjected': result['scpTVA'], | ||
'company_type': 'company'} | ||
addr = city = '' | ||
if result['adresa']: | ||
lines = [x for x in result['adresa'].replace( | ||
'NR,', 'NR.').split(",") if x] | ||
nostreet = True | ||
strlistabr = ['STR.', 'ALEEA', 'CAL.', 'INTR.', 'BD-UL'] | ||
for line in lines: | ||
if any([x in line for x in strlistabr]): | ||
nostreet = False | ||
break | ||
if nostreet: | ||
addr = 'Principala ' | ||
for line in lines: | ||
line = line.encode('utf8').translate( | ||
CEDILLATRANS).decode('utf8') | ||
if 'JUD.' in line: | ||
state = self.env['res.country.state'].search( | ||
[('name', | ||
'=', | ||
line.replace('JUD.', '').strip().title())]) | ||
if state: | ||
res['state_id'] = state[0].id | ||
elif 'MUN.' in line: | ||
city = line.replace('MUN.', '').strip().title() | ||
elif 'ORȘ.' in line: | ||
city = line.replace('ORȘ.', '').strip().title() | ||
elif 'COM.' in line: | ||
city += ' ' + line.strip().title() | ||
elif ' SAT ' in line: | ||
city += ' ' + line.strip().title() | ||
else: | ||
addr += line.replace('STR.', '').strip().title() + ' ' | ||
if city: | ||
res['city'] = city.replace('-', ' ').title().strip() | ||
res['street'] = addr.strip() | ||
return res | ||
|
||
@api.onchange('vat') | ||
def vies_vat_change(self): | ||
for partner in self: | ||
if not partner.vat: | ||
return {} | ||
res = {} | ||
vat = partner.vat.strip().upper() | ||
vat_country, vat_number = partner._split_vat(vat) | ||
try: | ||
if vat_country == 'ro': | ||
try: | ||
result = partner._get_Anaf(vat_number) | ||
if result: | ||
res = partner._Anaf_to_Odoo(result) | ||
except: | ||
_logger.info("ANAF Webservice not working.") | ||
if res: | ||
res['country_id'] = self.env['res.country'].search( | ||
[('code', 'ilike', vat_country)])[0].id | ||
partner.update(res) | ||
except: | ||
super(ResPartner, partner).vies_vat_change() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# © 2017 Forest and Biomass Services Romania | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_create_partner_by_vat |
58 changes: 58 additions & 0 deletions
58
l10n_ro_partner_create_by_vat/tests/test_create_partner_by_vat.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright 2017 Forest and Biomass Romania | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo.tests import common | ||
|
||
|
||
class TestCreatePartnerBase(common.SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super(TestCreatePartnerBase, cls).setUpClass() | ||
cls.mainpartner = cls.env.ref('base.res_partner_1') | ||
|
||
|
||
class TestCreatePartner(TestCreatePartnerBase): | ||
def test_vat_anaf(self): | ||
''' Check methods vat from ANAF.''' | ||
# Test retrive information from ANAF | ||
result = self.mainpartner._get_Anaf('30834857') | ||
if result: | ||
res = self.mainpartner._Anaf_to_Odoo(result) | ||
self.assertEqual(res['name'], 'FOREST AND BIOMASS ROMÂNIA S.A.') | ||
self.assertEqual(res['street'], | ||
'Cal. Buziașului Nr.11 A Corp B Zona Nr.2 Et.3') | ||
self.assertEqual(res['state_id'], self.env.ref('l10n_ro.RO_TM').id) | ||
self.assertEqual(res['city'], 'Timișoara') | ||
|
||
def test_onchange_vat_anaf(self): | ||
''' Check onchange vat from ANAF.''' | ||
# Test onchange from ANAF | ||
with self.env.do_in_onchange(): | ||
self.mainpartner.vat = 'RO30834857' | ||
self.mainpartner.vies_vat_change() | ||
self.assertEqual(self.mainpartner.name, | ||
'FOREST AND BIOMASS ROMÂNIA S.A.') | ||
self.assertEqual(self.mainpartner.street, | ||
'Cal. Buziașului Nr.11 A Corp B Zona Nr.2 Et.3') | ||
self.assertEqual(self.mainpartner.state_id, | ||
self.env.ref('l10n_ro.RO_TM')) | ||
self.assertEqual(self.mainpartner.city, 'Timișoara') | ||
self.assertEqual(self.mainpartner.country_id, | ||
self.env.ref('base.ro')) | ||
|
||
def test_onchange_vat_anaf(self): | ||
''' Check onchange vat from ANAF.''' | ||
# Test onchange from ANAF | ||
with self.env.do_in_onchange(): | ||
self.mainpartner.vat = 'RO8235738' | ||
self.mainpartner.vies_vat_change() | ||
self.assertEqual(self.mainpartner.name, | ||
'HOLZINDUSTRIE ROMANESTI S.R.L.') | ||
self.assertEqual(self.mainpartner.street, | ||
'Principala Românești Nr.69/A') | ||
self.assertEqual(self.mainpartner.state_id, | ||
self.env.ref('l10n_ro.RO_TM')) | ||
self.assertEqual(self.mainpartner.city, | ||
'Sat Românești Com. Tomești') | ||
self.assertEqual(self.mainpartner.country_id, | ||
self.env.ref('base.ro')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="view_partner_create_by_vat" model="ir.ui.view"> | ||
<field name="name">res.partner.create.by.vat</field> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base.view_partner_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="vat" position="after"> | ||
<label for="vat_subjected"/> | ||
<div name="vat_subjected_info" class="o_row"> | ||
<field name="vat_subjected" | ||
attrs="{'invisible': [ | ||
('vat', '=', False), | ||
('company_type', '=', 'company')]}"/> | ||
</div> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> | ||
|