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