Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
3 Besvarelser
2723 Visninger

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
Kassér
Forfatter

Please help

Forfatter Bedste svar

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
Kassér
Bedste svar

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
Kassér
Forfatter

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

Forfatter

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.

Bedste svar

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

Avatar
Kassér
Related Posts Besvarelser Visninger Aktivitet
3
jul. 25
2861
1
jun. 25
4614
2
maj 25
2792
1
maj 25
1842
1
feb. 25
40