Skip to Content
Menu
This question has been flagged
2 Replies
8909 Views

Hi,

I have a report with a non database table model which based on a SQL View, see below.

class ReportFee(models.Model):
_name = "fee.report"
_auto = False

        partner_id = fields.Many2one(comodel_name='res.partner', string='Partner', readonly=True)
percent = fields.Char(readonly=True)
invoice_id = fields.Char(readonly=True)
@api.multi
def button_create_inv(self):
print('OK')
        @api.model_cr
def init(self):
""" Event Question main report """
tools.drop_view_if_exists(self._cr, 'fee_report')
self._cr.execute(""" CREATE VIEW fee_report AS (
    SELECT
concat(account_invoice.id, fee_fee_line.fee_partner_id) as ID,
fee_fee_line.fee_partner_id as partner_id,
fee_fee_line.fee_percent as percent,
                account_invoice.number as invoice_id
FROM account_invoice
INNER JOIN fee_fee ON account_invoice.fee_identifier = fee_fee.id
INNER JOIN fee_fee_line ON fee_fee.id = fee_fee_line.fee_id
)""")

It works fine for the tree view. But if I click on an entry, the form view doesn't show any detail values. The button doesn't work, too.

Here my Form View Code:

<record id="view_form_fee_report" model="ir.ui.view" >
<field name="name">Fee List</field>
<field name="model">fee.report</field>
<field name="arch" type="xml">
        <form>
    <header>
               <button name="button_create_inv" type="object" string="Create Invoice" />
            </header>
    <group>
               <field name="partner_id"/>
               <field name="percent"/>
       <field name="invoice_id" />
    </group>
    </form>
</field>
</record>

Is it possible to have a detail form view for SQL View models which are no models in database and use buttons for actions?


Avatar
Discard
Author Best Answer

Thanks for your answer.

I solved the problem. It was the concat of the ID. It should always be an integer. With cast as integer the detail view works fine.

cast(concat(account_invoice.id, fee_fee_line.fee_partner_id) as integer) as ID
Avatar
Discard
Best Answer

Hello Silberlicht,

set Group by clause in query

SELECT
concat(account_invoice.id, fee_fee_line.fee_partner_id) as ID,
fee_fee_line.fee_partner_id as partner_id,
fee_fee_line.fee_percent as percent,
account_invoice.number as invoice_id
FROM account_invoice
INNER JOIN fee_fee ON account_invoice.fee_identifier = fee_fee.id
INNER JOIN fee_fee_line ON fee_fee.id = fee_fee_line.fee_id
GROUP BY partner_id, percent, invoice_id


Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
167
1
Sep 21
8138
1
Jan 24
15734
0
Mar 15
2343
1
Mar 15
8710