From 04795a165399b33682bb6725090712e4c20d3f6d Mon Sep 17 00:00:00 2001 From: blaggacao Date: Mon, 4 Aug 2014 17:24:15 -0500 Subject: [PATCH] res_partner_fiscal_document is borne --- res_partner_fiscal_document/__init__.py | 32 +++++ res_partner_fiscal_document/__openerp__.py | 59 ++++++++ .../data/res.partner.idtype.csv | 1 + .../res_partner_document.py | 134 ++++++++++++++++++ .../res_partner_document_view.xml | 20 +++ 5 files changed, 246 insertions(+) create mode 100644 res_partner_fiscal_document/__init__.py create mode 100644 res_partner_fiscal_document/__openerp__.py create mode 100644 res_partner_fiscal_document/data/res.partner.idtype.csv create mode 100644 res_partner_fiscal_document/res_partner_document.py create mode 100644 res_partner_fiscal_document/res_partner_document_view.xml diff --git a/res_partner_fiscal_document/__init__.py b/res_partner_fiscal_document/__init__.py new file mode 100644 index 000000000..4711b6bc0 --- /dev/null +++ b/res_partner_fiscal_document/__init__.py @@ -0,0 +1,32 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) Odoo Colombia (Community). +# Authors David Arnold (devCO) +# Juan Pablo Aries (devCO) +# +# Co-Authors Sandy Carter (Savaoirfairlinux) +# El Hadji Dem (Savoirfairelinux) +# Luis Miguel Varon +# Hector Ivan Valencia (TIX) +# +# Collaborators Nhomar Hernandez (Vauxoo) +# Humberto Ochoa (Vauxoo) +# +# 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 . +# +############################################################################## + +from . import res_partner_document \ No newline at end of file diff --git a/res_partner_fiscal_document/__openerp__.py b/res_partner_fiscal_document/__openerp__.py new file mode 100644 index 000000000..025299635 --- /dev/null +++ b/res_partner_fiscal_document/__openerp__.py @@ -0,0 +1,59 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) Odoo Colombia (Community). +# Authors David Arnold (devCO) +# Juan Pablo Aries (devCO) +# +# Co-Authors Sandy Carter (Savaoirfairlinux) +# El Hadji Dem (Savoirfairelinux) +# Luis Miguel Varon +# Hector Ivan Valencia (TIX) +# +# Collaborators Nhomar Hernandez (Vauxoo) +# Humberto Ochoa (Vauxoo) +# +# 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 . +# +############################################################################## + +{ + 'name': 'Partner Authentication with Fiscal Document', + 'description': """ +* Keep track of due legal identification of partners with a corresponing document. +* Register additional document types within the GUI. +* Easy hook for custom copy and validation/formatting methods (res_partner_document.py) +""", + 'category': 'Localization', + 'license': 'AGPL-3', + 'author': 'Juan Pablo Arias (devCO), David Arnold BA HSG (devCO)', + 'website': '', + 'version': '0.3', + 'depends': [ + 'base', + ], + 'data': [ + 'data/res.partner.idtype.csv', + 'res_partner_document_view.xml', + ], + 'demo': [ + #, + ], + 'test': [ + #, + ], + 'installable': True, + 'auto_install': False, +} \ No newline at end of file diff --git a/res_partner_fiscal_document/data/res.partner.idtype.csv b/res_partner_fiscal_document/data/res.partner.idtype.csv new file mode 100644 index 000000000..8cb44b279 --- /dev/null +++ b/res_partner_fiscal_document/data/res.partner.idtype.csv @@ -0,0 +1 @@ +id,name,code,sequence,active,note,on_company,on_contact diff --git a/res_partner_fiscal_document/res_partner_document.py b/res_partner_fiscal_document/res_partner_document.py new file mode 100644 index 000000000..9472cd4e3 --- /dev/null +++ b/res_partner_fiscal_document/res_partner_document.py @@ -0,0 +1,134 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) Odoo Colombia (Community). +# Author David Arnold (devCO) +# +# 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 . +# +############################################################################## + +from openerp import models, fields, api, _ + +class ResPartnerIDtype(models.Model): + _name = 'res.partner.idtype' + _description = 'Identification Document Type' + _order = 'sequence' + + name = fields.Char(required=True) + code = fields.Char(required=True) + sequence = fields.Integer() + active = fields.Boolean(default=True) + note = fields.Text() + on_company = fields.Boolean(string=u'On Company?') + on_contact = fields.Boolean(string=u'On Contact?', default=True) + + +class ResPartnerIdent(models.Model): + _name = 'res.partner' + _inherit = 'res.partner' + + dom = "['|', ('on_company', '=', is_company), ('on_contact', '!=', is_company)]" + fiscal_id_type = fields.Many2one( + 'res.partner.idtype', string=u'Document Type', domain=dom, + ) + fiscal_id = fields.Char(string=u'Document ID') + fiscal_id_doc = fields.Binary(string=u'Document Scan', + help="Upload the supporting Document preferably as size-optimized PDF. This might " + "help save disk space and PDF allows you to concatenate multiple documents.") + + + @api.one + @api.onchange( + 'fiscal_id_type', + 'fiscal_id', + # 'is_company', # https://github.com/odoo/odoo/issues/1530 + ) + def validateformatcopy(self): + # CASE: Current ID Type is not applicable on company + if self.is_company and not self.fiscal_id_type.on_company: + # Get the first valid ID type (remember: ordered by sequence) + self.fiscal_id_type = self.env['res.partner.idtype'].search([('on_company', '=', True)], limit=1).id + self.fiscal_id = None # Reset ID value + # CASE: Current ID Type is not applicable on contact + if not self.is_company and not self.fiscal_id_type.on_contact: + # Get the first valid ID type (remember: ordered by sequence) + self.fiscal_id_type = self.env['res.partner.idtype'].search([('on_contact', '=', True)], limit=1).id + self.fiscal_id = None # Reset ID value + # If everything is fine, call subclasses + if self.fiscal_id_type and self.fiscal_id: + # Function for String Operations + res = self._validateandformatid(self) + if res['output_type'] and res['output_id']: + self.fiscal_id_type, self.fiscal_id = res['output_type'], res['output_id'] + # Procedure for Copying + self._copyid(self) + + + @staticmethod + def _validateandformatid(self): + """ + Hook method to be inherited for custom validation methods. + :param input_type: the value of the field fiscal_id_type (id); passed on by onchange decorator + :param input_id: the value of the field fiscal_id (string); passed on by onchange decorator + :return: must return a dict with validated and formatted values + + Hint: + you might not alter the output_type unless you might want to build some kind of fiscal_id_type recognition + based on the input pattern into your hook method. CO###.###.###-# CO-VAT (NIT) for example. + + Find below a suggested basic outline. + + """ + f_type, f_id, is_company = self.fiscal_id_type, self.fiscal_id, self.is_company + + def default(): return {'output_type': f_type, 'output_id': f_id} + return { + 'CODE1': {'output_type': f_type, 'output_id': f_id}, + 'CODE2': {'output_type': f_type, 'output_id': f_id}, + # Define your cases with the index being the doctype id to match + # Note you can work inline (lambda), or call subfunctions at will + }.get(self.fiscal_id_type.code,default()) + + @staticmethod + def _copyid(self): + """ + Hook Method to be inherited for custom copy methods based on the document type (id) + Example Use Case: Copy some local VAT number into the VAT-Field in it's international format for compatibility. + + :return: It is a Procedure and therefore has no return value. + + Find below a suggested basic outline. + + """ + f_type, f_id, is_company = self.fiscal_id_type, self.fiscal_id, self.is_company + + def stringop_def(s): return s + def stringop_1(s): return re.match('\\d|\\w*', s) + # Define other Docstringoperatios if necessary + + def default(): + self.vat_subjected = True + # self.vat is a Boolean until base_vat is installed. + # self.vat = self.country_id.code + sringop_def(f_id) + + { + 'CODE1': {# self.vat_subjected: True, + # self.vat: self.country_id.code + stringop_1(f_id) + }, + 'CODE2': {# seld.vat_subjected: True, + # self.vat: self.country_id.code + stringop_1(f_id) + }, + }.get(self.fiscal_id_type.code, default()) diff --git a/res_partner_fiscal_document/res_partner_document_view.xml b/res_partner_fiscal_document/res_partner_document_view.xml new file mode 100644 index 000000000..7c209f3e8 --- /dev/null +++ b/res_partner_fiscal_document/res_partner_document_view.xml @@ -0,0 +1,20 @@ + + + + + + partner.form.authentication + res.partner + + form + + + + + + + + + + + \ No newline at end of file