Skip to Content
Menu
This question has been flagged

Hello.

I have some interesting issue. Basically I have extended the account.invoice module with a many2one field link to stock.warehouse. When I put some info from the warehouse to the invoice report, everything works fine. However, when I print multiple such invoices i get the following error:

ValueError: Expected singleton 

My code for the extension is quite simple, I guess i am missing something here:

class InvoiceWarehouse(models.Model):    
    _inherit = 'account.invoice'   
    warehouse_id = fields.Many2one('stock.warehouse', string="Warehouse", compute='_get_warehouse')
    def _get_warehouse(self):       
        for warehouse in self:             
            self.warehouse_id= self.env['sale.order'].search([('name', '=', self.origin)])[0].warehouse_id

Here is the Qweb element that is making problems

<div class="col-xs-6 col-xs-offset-0" style="white-space:nowrap; margin-top:25mm; font-size: 11px;" t-field="o.warehouse_id.company_id.report_header" name="moto"/>

Avatar
Discard
Best Answer

Hi,

In the last line of python code, use the warehouse instead of self as you are iterating the self.

for rec in self:
warehouse = self.env['sale.order'].search([('name', '=', rec.origin)], limit=1).warehouse_id.id
if warehouse:
rec.warehouse_id = warehouse


Thanks

Avatar
Discard
Author Best Answer

So I had a bad compute function. I would had never guessed that it is causing this issue. Thanks to Cybrosys Techno Solutions Pvt.Ltd  solution which pointed me to it, I did the following:

    def _get_warehouse(self):        
        for warehouse in self:           
            warehouse_id = self.env['sale.order'].search([('name', '=', warehouse.origin)], limit=1).warehouse_id.id           
            if warehouse_id:
                warehouse.warehouse_id = warehouse_id

Thank you so much

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
111
0
Aug 24
237
2
Nov 23
1472
5
Aug 23
8008
2
May 23
1262