Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Which is the best way to have the invoice number information in the stock move tree view?

By
Daniel Blanco
on 7/28/15, 7:48 AM 431 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?


1

Temur

--Temur--
2896
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 7/28/15, 8:03 AM

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

Thanks! I was very close!

Daniel Blanco
on 7/28/15, 8:31 AM

you're welcome

Temur
on 7/28/15, 9:20 AM
0

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3883
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 7/28/15, 8:21 AM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/28/15, 7:48 AM
Seen: 431 times
Last updated: 7/28/15, 9:23 AM