Browse Source

-> PEP8 styling

pull/21/head
blaggacao 11 years ago
parent
commit
0880200705
  1. 82
      res_partner_fiscal_document/res_partner_document.py

82
res_partner_fiscal_document/res_partner_document.py

@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
##############################################################################
# #############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) Odoo Colombia (Community).
@ -22,6 +22,7 @@
from openerp import models, fields, api, _
class ResPartnerIDtype(models.Model):
_name = 'res.partner.idtype'
_description = 'Identification Document Type'
@ -40,39 +41,42 @@ 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,
)
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.")
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
)
@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_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_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']
self.fiscal_id_type, self.fiscal_id = res['output_type'], res[
'output_id']
# Procedure for Copying
self._copyid(self)
@ -81,42 +85,54 @@ class ResPartnerIdent(models.Model):
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
: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.
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
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},
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())
"""
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.
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
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():
@ -124,11 +140,11 @@ class ResPartnerIdent(models.Model):
# 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,
{'CODE1': {
# self.vat_subjected: True,
# self.vat: self.country_id.code + stringop_1(f_id)
},
'CODE2': {# seld.vat_subjected: True,
'CODE2': {
# seld.vat_subjected: True,
# self.vat: self.country_id.code + stringop_1(f_id)
},
}.get(self.fiscal_id_type.code, default())
},}.get(self.fiscal_id_type.code, default())
Loading…
Cancel
Save