Help

0

How can I Inherit Existing Pivot, graph View Reports and add a field to "purchase.report" ?

Avatar
Jay

Hi,  I'm using  Odoo  14  and  I want to add price_unit from purchase_order_line to pivot and graph view of purchase.report. This will involve inheriting pivot and graph  of purchase.report model . 


Here is the error I'm getting .

error

psycopg2.errors.UndefinedColumn: column purchase_report.price_unit does not exist
LINE 3: ..._order_line" AS "purchase_report__price_unit" ON ("purchase_...
My Model
class PurchaseReport(models.Model):
_inherit = "purchase.report"

price_unit = fields.Many2one('purchase.order.line', string='Unit Price')
    
    def _query(self, with_clause='', fields={}, groupby='', from_clause=''):
fields['price_unit'] = ", s.price_unit as price_unit"
groupby += ', s.price_unit'
return super(PurchaseReport, self)._query(with_clause, fields, groupby, from_clause)



1 Comment
Avatar
Discard
Avatar
Jay
-

<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record model="ir.ui.view" id="view_purchase_order_inherit_pivot">
<field name="name">product.month.pivot.inherit</field>
<field name="model">purchase.report</field>
<field name="inherit_id" ref="purchase.view_purchase_order_pivot"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='untaxed_total']" position="before">
<field name="price_unit" type="col"/>
<field name="price_unit" type="measure"/>
</xpath>
</field>
</record>
<record model="ir.ui.view" id="view_purchase_order_inherit_graph">
<field name="name">product.month.graph.inherit</field>
<field name="model">purchase.report</field>
<field name="inherit_id" ref="purchase.view_purchase_order_graph"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='untaxed_total']" position="before">
<field name="price_unit" type="row"/>
<field name="price_unit" type="measure"/>
</xpath>
</field>
</record>

</odoo>

3 Answers
0
Avatar
Sunny Sheth
Best Answer
Hi,

You try below  solution,  it  will  work  for  you.

class PurchaseReport(models.Model):
_inherit = "purchase.report"
 
picking_type_id = fields.Many2one('stock.warehouse', 'Warehouse', readonly=True)


def _select(self):
return super(PurchaseReport, self)._select() + ", spt.warehouse_id as picking_type_id"

def _from(self):
return super(PurchaseReport, self)._from() + " left join stock_picking_type spt on (spt.id=po.picking_type_id)"

def _group_by(self):
return super(PurchaseReport, self)._group_by() + ", spt.warehouse_id"


Thanks and Regards,
Sunny Sheth
Avatar
Discard
0
Avatar
Jay
Best Answer

@Sunny and @Farid Thank you for taking your time to help.


Avatar
Discard
0
Avatar
Farid Ghanchi
Best Answer

You can just add new fields defination then add that fields is in Select and used in Groupby here we used l.price_unit because l meanse purchase_order_line.

Just apply this code and checked may be fixed your issue.

class PurchaseReport(models.Model):
       _inherit = "purchase.report"

       price_unit = fields.Many2one('purchase.order.line', string='Unit Price')

       def _select(self):
               return super(PurchaseReport, self)._select() + ", l.price_unit as price_unit"

       def _group_by(self):
               return super(PurchaseReport, self)._group_by() + ", l.price_unit"

Avatar
Discard