Skip to Content
Menu
This question has been flagged
3 Replies
1878 Views

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





Avatar
Discard
Author

Please help

Author 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

Avatar
Discard
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

Avatar
Discard
Author

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

Author

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?

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 25
1241
2
May 25
1356
1
May 25
683
1
Feb 25
38
1
Feb 25
1288