Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
1885 Vistas

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
Descartar
Autor

Please help

Autor Mejor respuesta

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
Descartar
Mejor respuesta

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
Descartar
Autor

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

Autor

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.

Mejor respuesta

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

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
jul 25
1383
1
jun 25
1287
2
may 25
1376
1
may 25
711
1
feb 25
38