Skip to content

Commit

Permalink
Merge branch '11.0' into 11.0-mig-l10n_ro_partner_unique
Browse files Browse the repository at this point in the history
  • Loading branch information
feketemihai committed Jan 23, 2018
2 parents cbd4dc2 + 10a2f8d commit b0ebed9
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Licence](https://img.shields.io/badge/licence-AGPL--3-blue.svg)
[![Runbot Status](https://runbot.odoo-community.org/runbot/badge/flat/177/11.0.svg)](https://runbot.odoo-community.org/runbot/repo/github-com-oca-l10n-romania-177)
[![Build Status](https://travis-ci.org/OCA/l10n-romania.svg?branch=11.0)](https://travis-ci.org/OCA/l10n-romania)
[![Coverage Status](https://coveralls.io/repos/OCA/l10n-romania/badge.png?branch=11.0)](https://coveralls.io/r/OCA/l10n-romania?branch=11.0)
[![Coverage Status](https://coveralls.io/repos/github/OCA/l10n-romania/badge.svg?branch=11.0)](https://coveralls.io/github/OCA/l10n-romania?branch=11.0)
[![codecov](https://codecov.io/gh/OCA/l10n-romania/branch/11.0/graph/badge.svg)](https://codecov.io/gh/OCA/l10n-romania)

Odoo Romania Localisation
Expand Down
77 changes: 77 additions & 0 deletions l10n_ro_partner_create_by_vat/README.rst
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:: 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.
1 change: 1 addition & 0 deletions l10n_ro_partner_create_by_vat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models, tests
16 changes: 16 additions & 0 deletions l10n_ro_partner_create_by_vat/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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',
'installable': True,
'depends': ['l10n_ro', 'base_vat_autocomplete'],
'data': ['views/res_partner_view.xml'],
}
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 ""

28 changes: 28 additions & 0 deletions l10n_ro_partner_create_by_vat/i18n/ro.po
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"

1 change: 1 addition & 0 deletions l10n_ro_partner_create_by_vat/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_partner
107 changes: 107 additions & 0 deletions l10n_ro_partner_create_by_vat/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Copyright (C) 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/v3/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, data=False):
# Function to get datas from ANAF Webservice
# cod = vat number without country code
# data = date of the interogation
if not data:
data = fields.Date.today()
res = requests.post(ANAF_URL, json=[{'cui': cod, 'data': data}],
headers=headers)
result = {}
if res.status_code == 200:
res = res.json()
if res['found'] and res['found'][0]:
result = res['found'][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()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions l10n_ro_partner_create_by_vat/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_create_partner_by_vat
66 changes: 66 additions & 0 deletions l10n_ro_partner_create_by_vat/tests/test_create_partner_by_vat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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'))
# Check inactive vatnumber
self.mainpartner.vat = 'RO27193515'
self.mainpartner.vies_vat_change()
self.assertEqual(self.mainpartner.name,
'FOREST AND BIOMASS SERVICES ROMANIA S.A.')
self.assertEqual(self.mainpartner.street,
'Cal. Buziașului Nr.11 A Corp B Zona Nr.1 Etaj 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'))
# Check address from commune
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'))
20 changes: 20 additions & 0 deletions l10n_ro_partner_create_by_vat/views/res_partner_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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>

2 changes: 2 additions & 0 deletions setup/l10n_ro_partner_create_by_vat/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal=1
6 changes: 6 additions & 0 deletions setup/l10n_ro_partner_create_by_vat/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit b0ebed9

Please sign in to comment.