A callback is a field’s value pre-process. It can be used for various treatments, such as striping, splitting, injecting data relative to the initial value, etc.
Note
Import the callback method and call it properly into the callbacks argument of a Field instanciation.
Concretely, it’s such as simple as that.
from csv2oerp import callbacks as cb
Model('res.parter_address', [
Field('partner_id', columns=[25], callbacks=[cb.get_id('res.partner', ['name'])]),
]
Model for the specifics callbacks class signature.
Parameters: |
|
---|
You can use a closure method to add specific arguments to your callback call.
def my_callback(*args, **kwargs):
""" Add some arguments to your callback
"""
def _callback(session, model, field, line):
result = ""
# Some treatments with arguments in scope
return result
return _callback
Here is the position of callbacks in the mapping hierarchy (Depending of your configuration, of course).
------ +-----+-----+---+--------+--------+---+-------+--------------+
|C |name |phone|fax|street |street2 |zip|country|... |
|S |-----|-----|---|--------|--------|---|-------|--------------|
|V |... |... |...|... |... |...|... |... |
------ +-----+-----+---+--------+--------+---+-------+--------------+
| | 1 | 2 | 3 | 4 | 5 | 6 | 7 |... |
| +--+--+--+--+-+-+----+---+--+-----++--+--+----+--------------+
|C | | | | | | |
|S | | | | | | |
|V +------------------------------------------------------------+
|2 | GLOBAL PRE-PROCESSES |
|O +------------------------------------------------------------+
|E | | | | | | |
|R | | | | | | |
|P | | | | +--+ | |
| | +-------------+ | | | +-------------+
|B | | callbacks | +-----+ | | | callbacks |
|I | +-------------+ | | | +-------------+
|N | | | | | | | |
|D | | | | | | | |
|S | | +--------+ | | | | |
| | +---------+ | | | | | |
| +---------+-+ | | | | | | |
------ | | | | | | | | |
| | | | | | | | | | +-----------+
| | | | | | | | | | |res.country|<-+
|O | | | | | | | | | |-----------| |
|P | | | | | | | | +-->|name | |
|E | | | | | | | +---->|code | |
|N | | | | | | | +-----------+ |
|E +-----------+ | | | | | | | +-------------------+ |
|R |res.partner| | | | | | | | |res.partner.address| |
|P |-----------| | | | | | | | |-------------------| |
| | name|<+ + | | | | +-->|zip | |
|M | | | | | | +------>|street2 | |
|O | | | | | +---------->|street | |
|D | | | | +-------------->|fax | |
|E | | | +------------------>|phone | |
|L | | +---------------------->|name | |
|S | addresses|-------------------------->|partner_id | |
| | | | country_id|-+
| | | | |
----- +-----------+ +-------------------+
Return a capitalized string.
Returns: | csv2oerp.callbaks.callback_model |
---|
Note
This function is a rewriting of string.capitalize, same signature
Check if a cedex code is in the town name. Return the relative string to res argument
Parameters: | |
---|---|
Returns: | csv2oerp.callbaks.callback_model |
Return a string.
Returns: | csv2oerp.callbaks.callback_model |
---|
Note
This function is a rewriting of base64, same signature
Return model‘s field field which fields‘s value matched value
Parameters: | |
---|---|
Returns: | csv2oerp.callbaks.callback_model |
Return model instance which one or more fields matched column value
Parameters: | |
---|---|
Returns: | csv2oerp.callbaks.callback_model |
Return model which one or more fields matched column value
Parameters: | |
---|---|
Returns: | csv2oerp.callbaks.callback_model |
Return model which one or more fields matched column value
Parameters: | |
---|---|
Returns: | csv2oerp.callbaks.callback_model |
Return model instance which fields‘s value matched value
Parameters: | |
---|---|
Returns: | csv2oerp.callbaks.callback_model |
Returns numbers contained in the columns values. Numbers must be in a french form such as 0123456789 or ‘+33123456789’ (No matters for spaces). Any other numbers must not be in the columns values.
Parameters: | |
---|---|
Returns: | csv2oerp.callbaks.callback_model |
Note
Example of a complex working string:
"The number of Mr SMITH is 0123456789, his wife 33 234 567 894, and their son 06 24 568495"
will returns independently of what type but with prefix (+33):
dict = {
'(field name)': ['(+33) 1 23 45 67 89', '(+33) 2 34 56 78 94'],
'mobile': ['(+33) 6 24 56 84 95'],
'all': ['(+33) 1 23 45 67 89', '(+33) 2 34 56 78 94', '(+33) 6 24 56 84 95'],
'value': "The number of Mr SMITH is 02XXXXXXXX, his wife 33 2XX XXXXXX, and their son 06 XX XX XX XX XX"
}
Search for an equivalence between value from column col_referer index and and value from args[3], and return value from column col_return index at the same line as matching pair col_referer values.
Parameters: | |
---|---|
Returns: | csv2oerp.callbaks.callback_model |
Note
This function is the csv2oerp.callbacks.search_csv() interface for callback call
Return a lowered string.
Returns: | csv2oerp.callbaks.callback_model |
---|
Note
This function is a rewriting of string.lower, same signature
>>> 'address': Column(3, lower())
Returns: | callback_model |
---|
Return a stripped string.
Returns: | csv2oerp.callbaks.callback_model |
---|
Note
This function is a rewriting of string.strip, same signature
Return a accents stripped string
Parameters: | |
---|---|
Returns: | csv2oerp.callbaks.callback_model |
Note
This function is a rewriting of unicodedata.normalize
Return a binary.
Returns: | csv2oerp.callbaks.callback_model |
---|
Note
This function is a rewriting of base64, same signature
Return a boolean depending from the input value.
Parameters: | |
---|---|
Returns: | csv2oerp.callbaks.callback_model |
Check for a valid date and convert if needed before returning the value
Parameters: | formatted (str) – Format of this date |
---|---|
Returns: | csv2oerp.callbaks.callback_model |