تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
5299 أدوات العرض

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?


الصورة الرمزية
إهمال
أفضل إجابة

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!

you're welcome

أفضل إجابة

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
الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يونيو 22
2374
3
مايو 21
5530
2
سبتمبر 20
2659
0
مارس 15
3748
1
أكتوبر 24
1920