Hi,
I create new table with union
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self._cr.execute("""
CREATE OR REPLACE VIEW %s AS
(
SELECT d.id as id,
d.sl_no as sl_no,
d.move_id,
d.company_id,
d.product_id,
d.mrp,
cast(d.mrp as text) as name
FROM (
SELECT a.id as id,
a.sl_no as sl_no,
a.move_id,
a.company_id,
a.product_id,
a.mrp,
cast(a.mrp as text) as name
FROM stock_move_line a
UNION
SELECT
sl.id as id,
sl.id as sl_no,
sl.id as move_id,
sl.company_id,
sl.product_id,
sl.mrp,
cast(sl.mrp as text) as name
FROM stock_inventory_line as sl)d where d.mrp is not null
)
""" % self._table)
but when i select a product in sale order that contains my table it shows error
"
psycopg2.errors.ObjectNotInPrerequisiteState: cannot update view "stock_mrp_product_report" DETAIL: Views that do not select from a single table or view are not automatically updatable. HINT: To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO IN
"
Thank you very much in advance
If you want to create this view for reporting purpose so use _auto = False in model definition. _auto = False means don't create a database table.
thank you for your response
when i update the stock_mrp_product_report with only one table it doesn't show any error.is there any other option ?
class ProductMRPReport(models.Model):
_name = "stock.mrp.product.report"
_description = "Product MRP"
_auto = False
_rec_name = "name"
_order = "id"
name = fields.Char(string='MRP')
sl_no = fields.Integer(string='sl')
product_id = fields.Many2one('product.product',string='product')
move_id = fields.Many2one('stock.move',string="Move")
company_id = fields.Many2one('res.company', string='Company')
mrp = fields.Float(string='MRP',default=0.0)