コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
8516 ビュー

Hi, I want to put on out invoices the name of the corresponding delivery slip . 

For this I try to find all the Invoice/delivery slip pairs with the same origin. So that you can choose inside a selection field between the delivery slips. 

But self is always account_invoice(). So I never get the active record to compare.

I hope someone can help. I have no Idea where to start with this...


thanks Chris

Code:

https://pastebin.com/uYetfdLu

class inv_text(models.Model):                                                                    

    _name = "account.invoice"                                                                    

    _inherit = "account.invoice"                                                                                                                

                                                                                                 

    delivery_ref = fields.Selection(selection='_get_delivery_name',string='Lieferschein')        

                                                                                                 

    @api.multi                                                                                    

    def _get_delivery_name(self):                                                                

        delivery_list = []                                                                                                                                                    

        deliverys = self.env["stock.picking"].search([("origin","=",self.origin)])                    

        for delivery in deliverys:                                                                

            delivery_list.append((str(delivery.name),str(delivery.name)))                                                                                                                

        return delivery_list

アバター
破棄
最善の回答

Hi Chris,


Try this.

from odoo import fields, model, api

class inv_text(models.Model):                                                                    
   
 _name = "account.invoice"                                                                    
    _inherit = "account.invoice"                                                                                                                
                                                                                                
    @api.model                                                                                    
    def _get_delivery_name(self):                                                                
 
delivery_list = []                                                                                                                                                    
        deliverys = self.env["stock.picking"].search([("origin","=",self.origin)])                    
    for delivery in deliverys:                                                                
          delivery_list.append((str(delivery.name),str(delivery.name)))                                                                                                                

        return delivery_list
     
     


delivery_ref = fields.Selection(selection=lambda self : self._get_delivery_name(), string='Lieferschein')      

Hope this will help.


Happy Odooing...

Regards,

Anil


アバター
破棄
著作者

Sadly, same output. If i print self inside the method for debug it's account.invoice().

I've structured your code, that how you can use the code while calling method directly in selection. it will work like default get method, you will not able to get data from self. if you want to fetch information from current object, use compute inside field and call your method in compute.

最善の回答

.

アバター
破棄
関連投稿 返信 ビュー 活動
1
2月 24
1990
1
5月 20
2863
1
7月 18
7378
1
11月 17
11608
4
8月 17
7324