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?