Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
2714 Vistas

I already have basic knowledge in SQL and I need to perform it in Odoo 15.

I want to create a list view using SQL and the datas are from two different model. sale.order.receivable.lines and account.move.line.

I already display the data.



but when I go to payment menu and set to draft the record, this error appears.

Avatar
Descartar
Mejor respuesta

Hello Lawrence,

We can achive this by creating a model with _auto = False attribute like below.

class AccountSaleRel(models.Model):
_name = 'account.sale.rel'
_description = 'Account Sale Rel'
_auto = False


account_move_line_id = fields.Many2one("account.move.line")
sale_order_receivable_lines_id = fields.Many2one("sale.order.receivable.lines")
f1 = fields.Char()
f2 = fields.Char()

c1 = fields.Boolean(compute="_compute_c1", store=False)
r1 = fields.Boolean(related="f1.active", store=False)


def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)

# We can only store fields fetched from below query like account_move_line_id, sale_order_receivable_lines_id, f1 and f2 fields. 
# rest of the fields should not be storable. 
self.env.cr.execute('''
CREATE OR REPLACE VIEW %s AS (
SELECT id as account_move_line_id, name as f1
FROM account_move_line 
FULL JOIN (SELECT id as sale_order_receivable_lines_id, name as f2 FROM sale.order.receivable.lines)
)''' % (self._table,)



def _compute_c1(self):
for rec in self:
rec.c1 = True

After this you can normally create tree view for 'account.sale.rel' model.

Reference of SQL views in Odoo: https://www.cybrosys.com/blog/how-to-create-sql-view-odoo

Hope it will be helpful to you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
dic 23
2679
2
ago 23
2348
1
dic 23
4117
1
jul 23
2950
0
may 23
2846