Hi, I would like to extend account_invoice.Invoice.search_total_amount[A] which is based on a python-sql query. It should be extended with another module. In my extension I would like to replace the following column[B]::
Coalesce(Sum(Round( ( line.quantity * line.unit_price).cast(type_name), currency.digits)), 0).as_('total_amount'), with something like this:: Coalesce(Sum(Round( ( line.quantity * line.unit_price * (1 - line.discount / 100.0) ).cast(type_name), currency.digits)), 0).as_('total_amount') The general boilerplate code in the other module looks like:: class Invoice: __metaclass__ = PoolMeta __name__ = 'account.invoice' @classmethod def search_total_amount(cls, name, clause): result = super(Invoice, cls).search_total_amount( name, clause) With introspection I found the column:: columns = list( result[0][2].columns[0].table.select.im_self .queries[0].columns) But I have no idea, how to replace the column, because I have not the correct line object from the depends module. When I try something like this:: pool = Pool() Line = pool.get('account.invoice.line') line = Line.__table__() columns[1] = Coalesce(Sum(Round(( line.quantity * line.unit_price * (1 - line.discount / 100.0) ).cast(type_name), currency.digits)), 0).as_('total_amount') result[0][2].columns[0].table.select.im_self.queries[0].columns = \ tuple(columns) the line table is wrong, I need the table from [B]. Questions: 1. Is it a good practice trying to extend python-sql? 2. Is there a better way to introspect the python-sql then this:: columns = list( result[0][2].columns[0].table.select.im_self .queries[0].columns) 3. How to get the line-object from the base sql? TIA and Regards Udo Spallek [A]http://hg.tryton.org/modules/account_invoice/file/tip/invoice.py#l741 [B] http://hg.tryton.org/modules/account_invoice/file/tip/invoice.py#l764 -- You received this message because you are subscribed to the Google Groups "tryton-dev" group. To view this discussion on the web visit https://groups.google.com/d/msgid/tryton-dev/20171230150819.645b27b7%40bender.fritz.box.
pgpYsbFljkH3x.pgp
Description: Digitale Signatur von OpenPGP