Project
Function
Sample CLI
gway odoo fetch-templates
References
['error']
Full Code
def fetch_templates(*, name=None, active=True, **kwargs):
"""
Fetch available quotation templates from Odoo with optional filters.
Parameters:
name (str, optional): Filter templates by name or part of it.
active (bool): Whether to include only active templates. Defaults to True.
**kwargs: Additional filters as key-value pairs.
Returns:
dict: The fetched quotation templates.
"""
model = 'sale.order.template'
method = 'search_read'
domain_filter = []
if name:
domain_filter.append(('name', 'ilike', name))
if active is not None:
domain_filter.append(('active', '=', active))
for field, value in kwargs.items():
domain_filter.append((field, '=', value))
fields_to_fetch = ['name', 'number_of_days', 'active']
try:
result = execute_kw(
[domain_filter], {'fields': fields_to_fetch},
model=model, method=method
)
return result
except Exception as e:
gw.error(f"Error fetching quotation templates: {e}")
raise