Add multi client template management
This commit is contained in:
@@ -2,6 +2,9 @@ from decimal import Decimal, ROUND_HALF_UP
|
||||
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.modules.purchase_trade.numbers_to_words import amount_to_currency_words
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.modules.account_invoice.invoice import (
|
||||
InvoiceReport as BaseInvoiceReport)
|
||||
|
||||
|
||||
class Invoice(metaclass=PoolMeta):
|
||||
@@ -665,3 +668,62 @@ class InvoiceLine(metaclass=PoolMeta):
|
||||
if net == '':
|
||||
return ''
|
||||
return round(Decimal(net) * Decimal('2204.62'),2)
|
||||
|
||||
|
||||
class InvoiceReport(BaseInvoiceReport):
|
||||
__name__ = 'account.invoice'
|
||||
|
||||
@classmethod
|
||||
def _get_purchase_trade_configuration(cls):
|
||||
Configuration = Pool().get('purchase_trade.configuration')
|
||||
configurations = Configuration.search([], limit=1)
|
||||
return configurations[0] if configurations else None
|
||||
|
||||
@classmethod
|
||||
def _get_action_name(cls, action):
|
||||
if isinstance(action, dict):
|
||||
return action.get('name') or ''
|
||||
return getattr(action, 'name', '') or ''
|
||||
|
||||
@classmethod
|
||||
def _resolve_configured_report_path(cls, action):
|
||||
config = cls._get_purchase_trade_configuration()
|
||||
report_path = cls._get_action_report_path(action) or ''
|
||||
action_name = cls._get_action_name(action)
|
||||
|
||||
if (report_path.endswith('/prepayment.fodt')
|
||||
or action_name == 'Prepayment'):
|
||||
template = (
|
||||
getattr(config, 'invoice_prepayment_report_template', '')
|
||||
if config else '')
|
||||
elif (report_path.endswith('/invoice_ict_final.fodt')
|
||||
or action_name == 'CN/DN'):
|
||||
template = (
|
||||
getattr(config, 'invoice_cndn_report_template', '')
|
||||
if config else '')
|
||||
else:
|
||||
template = (
|
||||
getattr(config, 'invoice_report_template', '')
|
||||
if config else '')
|
||||
|
||||
template = (template or '').strip()
|
||||
if not template:
|
||||
raise UserError('No template found')
|
||||
if '/' not in template:
|
||||
return f'account_invoice/{template}'
|
||||
return template
|
||||
|
||||
@classmethod
|
||||
def _get_resolved_action(cls, action):
|
||||
report_path = cls._resolve_configured_report_path(action)
|
||||
if isinstance(action, dict):
|
||||
resolved = dict(action)
|
||||
resolved['report'] = report_path
|
||||
return resolved
|
||||
setattr(action, 'report', report_path)
|
||||
return action
|
||||
|
||||
@classmethod
|
||||
def _execute(cls, records, header, data, action):
|
||||
resolved_action = cls._get_resolved_action(action)
|
||||
return super()._execute(records, header, data, resolved_action)
|
||||
|
||||
Reference in New Issue
Block a user