Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
5292 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää
Tekijä

Thanks! I was very close!

you're welcome

Paras vastaus

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
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
kesäk. 22
2374
3
toukok. 21
5526
2
syysk. 20
2658
0
maalisk. 15
3745
1
lokak. 24
1917