Skip to Content
Menu
This question has been flagged
2 Replies
4370 Views

A pair of customers have this same problem: they neet to quickly see the stock movement linked to the invoice.

Since there is no direct link between stock move and invoice, I want to lean myself in the fact they are using the pos. This way I found that picking_id is in stock.move, and in pos.order. Then pos.order has invoice_id as a field.

So I wrote something like this:

class stock_move_invoice_number(models.Model):
_name = "stock.move"
_inherit = "stock.move"

invoice_number = fields.Char(
string='Invoice Number', compute='_get_inv_number', help='Invoice Number'
)

@api.depends('picking_id')
def _get_inv_number(self):
for x in self:
print x.picking_id
po = x.env['pos.order'].search([('picking_id', '=', x.picking_id)], limit=1)
x.invoice_number = po.invoice_id.afip_document_number

But I get an error in the domain:

AssertionError: Invalid value stock.picking(1150,) in domain term ('picking_id', '=', stock.picking(1150,))

If I hardcode the value 1150 as int in the domain, I am getting what I need, so the idea works, but I can't catch the picking_id number away from the x.picking_id object.

Is there a better approach?


Avatar
Discard
Best Answer

use x.picking_id.id instead of x.picking_id

x.picking_id -is a record in this case, whereas x.picking_id.id is id field of this record, you can access any other field as well, using: x.picking_id.field_name

Avatar
Discard
Author

Thanks! I was very close!

you're welcome

Best Answer

For a many2one field, you have the database ID of relational model stored in the database.

In order to search the picking_id, you need to use the database id to check it rather than with picking object(stock.picking(1150,)).
If you change the search using picking_id.id, then you would get the database id of that picking record (as per Temur's suggestion)


   @api.depends('picking_id')
def _get_inv_number(self):
for x in self:
print x.picking_id
po = x.env['pos.order'].search([('picking_id', '=', x.picking_id.id)], limit=1)
x.invoice_number = po.invoice_id.afip_document_number
Avatar
Discard
Related Posts Replies Views Activity
1
Jun 22
1115
3
May 21
3849
2
Sep 20
1618
0
Mar 15
3002
1
Oct 24
318