1

I want to add a custom field to the Product Moves reporting in Inventory > Reporting menu.

I try with this code but I got always an undefined value. What's wrong please?

 class stockMoveLine(models.Model):

    _inherit = 'stock.move.line'

    categ_id = fields.Many2one('product.category', 'Product Category', readonly=True)
    
        def _query(self, with_clause='', fields={}, groupby='', from_clause=''):
            fields['categ_id'] = ', s.categ_id as categ_id'
            groupby += ', s.categ_id'
            return super(stockMoveLine, self)._query(with_clause, fields, groupby, from_clause)

Thanks.

Ing
  • 551
  • 7
  • 20
  • Can you post a Minimal Reproducible Example https://stackoverflow.com/help/minimal-reproducible-example and/or show the output of the error ? Which are your models ? What is that is "undefined" ? – RobyB Nov 01 '21 at 10:23
  • @RobyB when I grouped by categ_id , I got 'undefined' in pivot view , although , I set category for my products. – Ing Nov 01 '21 at 10:32
  • You got `undefined` because `categ_id` field is not set. What does the `_query` function do? – Kenly Nov 01 '21 at 11:19
  • @Ing explain this in the code in your post, not to me and, again, please shre the exact output of the error. (Stacktrace) – RobyB Nov 01 '21 at 12:44

1 Answers1

3

You are getting the undefined because your custom field (categ_id) can not hold the data and there is not any usage here for the def _query function.

I believed you might be thinking this would be the analysis view but no this is just the normal view of the model.

On Pivot to play around with different fields and analysis purposes you can do by this way,

In the stock.move.line object put the related field of product->product.category like you did here but just make as the related of this and put the store=True

and you can add this new field in the pivot view or use it in the search view with that you can use on a pivot follow by search filter or groupby.

Dipen Shah
  • 2,396
  • 2
  • 9
  • 21