From 0c24872a15a2ba989ef6f119ee3652e5f8a3877c Mon Sep 17 00:00:00 2001 From: Remi <remi@le-filament.com> Date: Tue, 23 Apr 2019 16:54:52 +0200 Subject: [PATCH] Align with module proposed to OCA, fix coding according to standards --- LICENSE | 29 +----- README.rst | 2 + __init__.py | 5 +- __manifest__.py | 33 +++--- models/__init__.py | 3 +- models/res_partner.py | 26 +++-- views/res_partner.xml | 62 +++++------ wizard/__init__.py | 3 +- wizard/wizard_siren.py | 220 +++++++++++++++++++--------------------- wizard/wizard_siren.xml | 2 + 10 files changed, 178 insertions(+), 207 deletions(-) diff --git a/LICENSE b/LICENSE index 7e5dad2..fb0e255 100644 --- a/LICENSE +++ b/LICENSE @@ -200,31 +200,4 @@ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY C If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. -END OF TERMS AND CONDITIONS - -How to Apply These Terms to Your New Programs - -If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. - -To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - 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 <https://www.gnu.org/licenses/>. -Also add information on how to contact you by electronic and paper mail. - -If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. - -You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. \ No newline at end of file +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/README.rst b/README.rst index c71e5c7..fdad646 100644 --- a/README.rst +++ b/README.rst @@ -28,6 +28,8 @@ Le module crée un wizard disponible pour les société qui met à jour les info Ce module utilise l'api mise à disposition par l'INSEE et disponible à l'adresse suivante : https://data.opendatasoft.com/api/records/1.0/search/ +Ce module a été traduit en anglais, la partie ESS enlevée (car considérée pas assez générique) et proposé à l'OCA en v10 (https://github.com/OCA/l10n-france/pull/163) et v12 (https://github.com/OCA/l10n-france/pull/173) + Usage ===== diff --git a/__init__.py b/__init__.py index eb6cc70..4218e82 100644 --- a/__init__.py +++ b/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -import models -import wizard \ No newline at end of file +from . import models +from . import wizard diff --git a/__manifest__.py b/__manifest__.py index db8709c..30e5a6a 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -1,25 +1,26 @@ # -*- coding: utf-8 -*- -# © 2017 Le Filament (<http://www.le-filament.com>) +# © 2018 Le Filament (<https://www.le-filament.com>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Le Filament - SIREN', - 'summary': "Recherche dans la base SIREN", - 'version': '10.0.1.0', - 'license': 'AGPL-3', - 'author': 'LE FILAMENT', - 'category': 'Partner', - 'depends': ['base'], - 'contributors': [ + 'name': 'Le Filament - SIREN', + 'summary': "Recherche dans la base SIREN", + 'version': '10.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'LE FILAMENT', + 'category': 'Partner', + 'depends': ['base'], + 'contributors': [ 'Benjamin Rivier <benjamin@le-filament.com>', + 'Rémi Cazenave <remi@le-filament.com>', ], - 'website': 'http://www.le-filament.com', - 'data': [ - 'wizard/wizard_siren.xml', - 'views/res_partner.xml', - ], - 'qweb': [ + 'website': 'https://www.le-filament.com', + 'data': [ + 'wizard/wizard_siren.xml', + 'views/res_partner.xml', + ], + 'qweb': [ 'static/src/xml/*.xml', ], -} \ No newline at end of file +} diff --git a/models/__init__.py b/models/__init__.py index 1198bf1..2d6da85 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -import res_partner \ No newline at end of file +from . import res_partner diff --git a/models/res_partner.py b/models/res_partner.py index 1d3b257..34768b2 100644 --- a/models/res_partner.py +++ b/models/res_partner.py @@ -3,21 +3,19 @@ # © 2018 Le Filament (<http://www.le-filament.com>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import api, fields, models +from odoo import fields, models class PartnerSiren(models.Model): - _inherit = 'res.partner' + _inherit = 'res.partner' - ## Fields - forme_juridique = fields.Char("Forme Juridique") - siren = fields.Char("SIREN") - siret = fields.Char("SIRET") - ape = fields.Char("Code APE") - lib_ape = fields.Char("Libellé APE") - date_creation = fields.Date("Date de création") - effectif = fields.Char("Effectif") - lib_ess = fields.Char("Libellé ESS") - date_ess = fields.Date("Date ESS") - ess = fields.Boolean("ESS") - categorie = fields.Char("Catégorie") \ No newline at end of file + # Fields + forme_juridique = fields.Char("Forme Juridique") + siren = fields.Char("SIREN") + siret = fields.Char("SIRET") + ape = fields.Char("Code APE") + lib_ape = fields.Char("Libellé APE") + date_creation = fields.Date("Date de création") + effectif = fields.Char("Effectif") + ess = fields.Boolean("ESS") + categorie = fields.Char("Catégorie") diff --git a/views/res_partner.xml b/views/res_partner.xml index 3682f32..18de112 100644 --- a/views/res_partner.xml +++ b/views/res_partner.xml @@ -1,13 +1,14 @@ <?xml version="1.0" encoding="utf-8"?> +<!-- Copyright 2018 Le Filament (<https://www.le-filament.com>) + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> <odoo> - <data> - - <!-- Client Form View --> - <record id="partner_form_siren_view" model="ir.ui.view"> - <field name="name">res.partner.siren.form.view</field> - <field name="model">res.partner</field> - <field name="inherit_id" ref="base.view_partner_form"/> - <field name="arch" type="xml" > + <data> + <!-- Client Form View --> + <record id="partner_form_siren_view" model="ir.ui.view"> + <field name="name">res.partner.siren.form.view</field> + <field name="model">res.partner</field> + <field name="inherit_id" ref="base.view_partner_form"/> + <field name="arch" type="xml" > <!-- ADD HEADER BUTTON --> <xpath expr="//sheet" position="before"> <header attrs="{'invisible': [('is_company','!=',True)]}"> @@ -16,28 +17,27 @@ </xpath> <!-- ADD PARTNER INFO TAB --> <xpath expr="//page[@name='internal_notes']" position="after" attrs="{'invisible': [('is_company','!=',True)]}"> - <page name="legal_infos" string="Infos Légales"> - <group> - <group string="Infos légales"> - <field name="forme_juridique" /> - <field name="siren" /> - <field name="siret" /> - <field name="ape" /> - <field name="lib_ape" /> - </group> - <group string="Infos Entreprise"> - <field name="categorie" /> - <field name="date_creation" /> - <field name="effectif" /> - </group> - <group string="ESS"> - <field name="ess" /> - </group> - </group> - </page> + <page name="legal_infos" string="Infos Légales"> + <group> + <group string="Infos légales"> + <field name="forme_juridique" /> + <field name="siren" /> + <field name="siret" /> + <field name="ape" /> + <field name="lib_ape" /> + </group> + <group string="Infos Entreprise"> + <field name="categorie" /> + <field name="date_creation" /> + <field name="effectif" /> + </group> + <group string="ESS"> + <field name="ess" /> + </group> + </group> + </page> </xpath> - </field> - </record> - - </data> + </field> + </record> + </data> </odoo> diff --git a/wizard/__init__.py b/wizard/__init__.py index 54eb1ae..5fc4b17 100644 --- a/wizard/__init__.py +++ b/wizard/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -import wizard_siren \ No newline at end of file +from . import wizard_siren diff --git a/wizard/wizard_siren.py b/wizard/wizard_siren.py index 7ccc2c9..da4e03b 100644 --- a/wizard/wizard_siren.py +++ b/wizard/wizard_siren.py @@ -1,127 +1,119 @@ # -*- coding: utf-8 -*- -# © 2018 Le Filament (<http://www.le-filament.com>) +# © 2018 Le Filament (<https://www.le-filament.com>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import json -import urllib2 import requests from odoo import api, fields, models -URL = "https://data.opendatasoft.com/api/records/1.0/search/?dataset=sirene_v3%40public&q=" -CHAMPS = "&rows=100" +URL = "https://data.opendatasoft.com/api/records/1.0/"\ + "search/?dataset=sirene_v3%40public&q={request}&rows=100" + class SirenWizard(models.TransientModel): - _name = 'siren.wizard' - _description = 'Get values from companies' - - - ## Default functions - @api.model - def _default_name(self): - return self.env['res.partner'].browse(self.env.context.get('active_id')).name - - @api.model - def _default_partner(self): - return self.env.context.get('active_id') - - ## Fields - name = fields.Char(string='Entreprise', default=_default_name) - city = fields.Char(string='Ville') - company_lines = fields.One2many('siren.wizard.company', 'wizard_id', string="Résultats",) - partner_id = fields.Integer('Partner', default=_default_partner) - - - ## Action - def get_company_lines(self): - # Get request - r = requests.get(URL + self.name + CHAMPS) - # Serialization request to JSON - companies = r.json() - # Unlink all company lines - self.company_lines.unlink() - # Fill new company company_lines - for company in companies['records']: - if company['fields'].get('denominationunitelegale',False): - new_company = self.company_lines.create({ - 'wizard_id': self.id, - 'name': company['fields'].get('denominationunitelegale'), - }) - if company['fields'].get('adresseetablissement'): - new_company.street = company['fields']['adresseetablissement'] - if company['fields'].get('codepostaletablissement'): - new_company.zip = company['fields']['codepostaletablissement'] - if company['fields'].get('libellecommuneetablissement'): - new_company.city = company['fields']['libellecommuneetablissement'] - if company['fields'].get('siren'): - new_company.siren = company['fields']['siren'] - if company['fields'].get('siret'): - new_company.siret = company['fields']['siret'] - if company['fields'].get('categorieentreprise'): - new_company.categorie = company['fields']['categorieentreprise'] - if company['fields'].get('datecreationunitelegale'): - new_company.date_creation = company['fields']['datecreationunitelegale'] - if company['fields'].get('activiteprincipaleunitelegale'): - new_company.ape = company['fields']['activiteprincipaleunitelegale'] - if company['fields'].get('divisionunitelegale'): - new_company.lib_ape = company['fields']['divisionunitelegale'] - if company['fields'].get('economiesocialesolidaireunitelegale') == "O": - new_company.ess = True - if company['fields'].get('naturejuridiqueunitelegale'): - new_company.forme_juridique = company['fields']['naturejuridiqueunitelegale'] - if company['fields'].get('trancheeffectifsunitelegale', "0") in ["NN","0"]: - new_company.effectif = 0 - else: - new_company.effectif = int(company['fields'].get('trancheeffectifsunitelegale')) - - return { "type": "ir.actions.do_nothing", } + _name = 'siren.wizard' + _description = 'Get values from companies' + + # Default functions + @api.model + def _default_name(self): + return self.env['res.partner'].browse( + self.env.context.get('active_id')).name + + @api.model + def _default_partner(self): + return self.env.context.get('active_id') + + # Fields + name = fields.Char(string='Entreprise', default=_default_name) + city = fields.Char(string='Ville') + company_lines = fields.One2many('siren.wizard.company', + 'wizard_id', string="Résultats",) + partner_id = fields.Integer('Partner', default=_default_partner) + + # Action + @api.model + def _prepare_partner_from_data(self, data): + return { + 'name': data.get('denominationunitelegale'), + 'street': data.get('adresseetablissement', False), + 'zip': data.get('codepostaletablissement', False), + 'city': data.get('libellecommuneetablissement', False), + 'siren': data.get('siren', False), + 'siret': data.get('siret', False), + 'categorie': data.get('categorieentreprise', False), + 'date_creation': data.get('datecreationunitelegale', + False), + 'ape': data.get('activiteprincipaleunitelegale', False), + 'lib_ape': data.get('divisionunitelegale', False), + 'forme_juridique': data.get('naturejuridiqueunitelegale', False), + 'effectif': data.get('trancheeffectifsunitelegale', 0), + 'ess': (True if data.get('economiesocialesolidaireunitelegale') + else False), + } + + def get_company_lines(self): + # Get request + r = requests.get(URL.format(request=self.name)) + # Serialization request to JSON + companies = r.json() + # Fill new company lines + companies_vals = [] + for company in companies['records']: + res = self._prepare_partner_from_data(company['fields']) + companies_vals.append((0, 0, res)) + self.company_lines.unlink() + self.company_lines = companies_vals + return { + 'context': self.env.context, + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'siren.wizard', + 'res_id': self.id, + 'view_id': False, + 'type': 'ir.actions.act_window', + 'target': 'new', + } class SirenWizardCompanies(models.TransientModel): - _name = 'siren.wizard.company' - _description = 'Companies Selection' - - ## Fields - wizard_id = fields.Many2one('siren.wizard', string='Wizard',) - name = fields.Char(string='Nom') - street = fields.Char(string='Rue') - zip = fields.Char(string='CP') - city = fields.Char(string='Ville') - - forme_juridique = fields.Char("Forme Juridique") - siren = fields.Char("SIREN") - siret = fields.Char("SIRET") - ape = fields.Char("Code APE") - lib_ape = fields.Char("Libellé APE") - date_creation = fields.Date("Date de création") - effectif = fields.Char("Effectif") - lib_ess = fields.Char("Libellé ESS") - date_ess = fields.Date("Date ESS") - ess = fields.Boolean("ESS", default=False) - categorie = fields.Char("Catégorie") - - - ## Action - @api.multi - def update_partner(self): - partner = self.env['res.partner'].browse(self.wizard_id.partner_id) - partner.write({ - 'name': self.name, - 'street': self.street, - 'zip': self.zip, - 'city': self.city, - 'forme_juridique': self.forme_juridique, - 'siren': self.siren, - 'siret': self.siret, - 'ape': self.ape, - 'lib_ape': self.lib_ape, - 'date_creation': self.date_creation, - 'effectif': self.effectif, - 'lib_ess': self.lib_ess, - 'date_ess': self.date_ess, - 'ess': self.ess, - 'categorie': self.categorie, - }) - - return True + _name = 'siren.wizard.company' + _description = 'Companies Selection' + + # Fields + wizard_id = fields.Many2one('siren.wizard', string='Wizard',) + name = fields.Char(string='Nom') + street = fields.Char(string='Rue') + zip = fields.Char(string='CP') + city = fields.Char(string='Ville') + + forme_juridique = fields.Char("Forme Juridique") + siren = fields.Char("SIREN") + siret = fields.Char("SIRET") + ape = fields.Char("Code APE") + lib_ape = fields.Char("Libellé APE") + date_creation = fields.Date("Date de création") + effectif = fields.Char("Effectif") + ess = fields.Boolean("ESS", default=False) + categorie = fields.Char("Catégorie") + + # Action + @api.multi + def update_partner(self): + partner = self.env['res.partner'].browse(self.wizard_id.partner_id) + partner.write({ + 'name': self.name, + 'street': self.street, + 'zip': self.zip, + 'city': self.city, + 'forme_juridique': self.forme_juridique, + 'siren': self.siren, + 'siret': self.siret, + 'ape': self.ape, + 'lib_ape': self.lib_ape, + 'date_creation': self.date_creation, + 'effectif': self.effectif, + 'ess': self.ess, + 'categorie': self.categorie, + }) diff --git a/wizard/wizard_siren.xml b/wizard/wizard_siren.xml index 3dd4408..a415981 100644 --- a/wizard/wizard_siren.xml +++ b/wizard/wizard_siren.xml @@ -1,4 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- Copyright 2018 Le Filament (<https://www.le-filament.com>) + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> <odoo> <!-- WIZARD FORM --> <record id="siren_wizard_view_form" model="ir.ui.view"> -- GitLab