Skip to Content
Menu
This question has been flagged
3 Replies
2696 Rodiniai

Dear Odoo Community,

I am currently working on customizing the sale.report model by adding a new custom field. Despite following the appropriate steps, I am encountering an error stating that the custom field cannot be found.


Could anyone provide guidance on how to resolve this issue? Specifically:

  • What could be causing the 'field not found' error in this context?
  • Are there any additional steps I need to take to ensure the custom field is correctly recognized and included in the sale.report?
  • How can I confirm that my SQL query correctly reflects the new field and its source?

Any help or suggestions would be greatly appreciated!

Thank you in advance for your assistance.



here's my python code -


from odoo import _, api, fields, models



class SWMSaleReport(models.Model):

    _inherit = 'sale.report'


    partner_township_id = fields.Many2one('res.country.township', string="Township", related='partner_id.township_id')



    def _select_additional_fields(self):

        res = super()._select_additional_fields()

        # Correct SQL syntax without 'AS'

        res['partner_township_id'] = f"""s.partner_township_id

        """

        return res





Portretas
Atmesti
Autorius

Please help

Autorius Best Answer

Here's the method that is worked on me - 


class SaleReport(models.Model):

​_inherit = 'sale.report'

​​partner_township_id = fields.Many2one(comodel_name='res.country.township', string="Township", readonly=True)

​sale_order_type_id = fields.Many2one('swm.sale.type', string="Sale Order Type")


    ​def _select_additional_fields(self):

​​res = super()._select_additional_fields()

​res['partner_township_id'] = "partner.township_id"

​res['sale_order_type_id'] = "s.sale_order_type_id"

​return res

   

​def _group_by_sale(self):

​res = super()._group_by_sale()

​res += """, partner.township_id, s.sale_order_type_id,""" 

​return res

Portretas
Atmesti
Best Answer

Hi,
Try as follows:

    ​partner_township_id = fields.Many2one('res.country.township', string="Township")


    def _select_additional_fields(self):

        res = super()._select_additional_fields()

        res['partner_township_id'] = """partner.partner_township_id"""

        return res

Thanks

Portretas
Atmesti
Autorius

But it's still saying - psycopg2.errors.UndefinedColumn: column partner.partner_township_id does not exist
LINE 64: partner.partner_township_id AS partner_township_...

actually to this report, from which model you need to take the partner_township_id data/field

Autorius

Dear Mr. @Niyas,

Good Morning,

Thank you for your help.
After find at the Odoo Logs, it said in order to work at Dashboard and Reports, our custom fields need to be added under _group_by_sale function.

Best Answer

Please can you tell givie me step-by-step method on how you did it?

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
3
liep. 25
2844
1
birž. 25
4578
2
geg. 25
2786
1
geg. 25
1835
1
vas. 25
40