Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
3 Antwoorden
2706 Weergaven

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
Annuleer
Auteur

Please help

Auteur Beste antwoord

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

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

Auteur

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.

Beste antwoord

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

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
3
jul. 25
2844
1
jun. 25
4589
2
mei 25
2786
1
mei 25
1840
1
feb. 25
40