Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
24101 Lượt xem

I added a filed company(It's a char field), when creating a payment ,I want to set default value. When creating new payment, the value wasn't displayed in the form view . 
I  have problem on condition if self.payment_type == 'outbound', it is not entering in if condition.                     Any help please? What's wrong in my code ?
class AccountPayment(models.Model):

     _inherit = "account.payment"    


    def get_company(self):
        if self.payment_type == 'outbound':
            my_company = self.env.user.company_id.name
            return my_company
        else:
            return None

    company = fields.Char(string='Company Name', default=get_company)

Thanks.

Ảnh đại diện
Huỷ bỏ

No issue with code ,

try printing payment_type before if condition and check its outbound or not .

Tác giả

I got always a 'False' value in payment_type . @Kiran Mohan

Câu trả lời hay nhất

Try this

def get_company(self):
        if self._context['default_payment_type'] == 'outbound':
            return self.env.user.company_id.name
        else: return None

Regards


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 24
6364
2
thg 9 21
12786
1
thg 8 21
8337
1
thg 7 21
4337
1
thg 12 23
29072