콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
5382 화면

Hi

I have a receipt form that lets you register payments. Now I wanna take the amount entered AFTER pressing the validate button and use it in another model. How can I do that?

아바타
취소
베스트 답변

Hi,

you must have a relation field between class account voucher (but you do not give this information), with example I give after, with field voucher_id in class record, and use a field type related or function (use function type for better performance) depending of the amount field in class voucher which will give the value in the field amount in record class when field amount change in class voucher.

Never use an onchange for that because if I do a write from a function in current class or a write from an other class in this field, the onchange will be not used and the value will not change in the record class.



from openerp import models, fields, api


class Record(models.Model):

    _name= 'record'

   

    voucher_id = fields.Many2one('account.voucher', 'Voucher')

    amount = fields.Float(compute='_get_voucher_amount', string='Voucher amount')


    @api.one

    @api.depends('voucher_id', 'voucher_id.amount')

    def _get_voucher_amount(self):

        self.amount = self.voucher_id.amount

Bye

아바타
취소
작성자

I'm getting this error when I run it: ProgrammingError: column record.voucher_id does not exist

작성자

Hi Cyril, I managed to get it working. But in my 'amount':fields.float(compute='_get_voucher_amount',string="Voucher Amount"), the _get_voucher_amount is not getting called. I have put a print statement in it but it just doesn't show.

update my code, forgot to add voucher_id in @depends, now when you will change voucher_id in class record, or amount in class account voucher, amount in class record will be updated, bye

작성자

Cyril still the function _get_voucher_amount is not getting called..

베스트 답변

here i using odoo 8. after press the amount in account.voucher model. u can get the amount value in another model. for that u just simply inherit the model in ur current model and use that value in ur current model.

from openerp import models, fields, api, _

class account_voucher(models.Model):

_inherit = 'account.voucher'

@api.multi

def onchange_amount(self, amount, rate, partner_id, journal_id, currency_id, ttype, date, payment_rate_currency_id, company_id):

print amount

return True

아바타
취소
작성자

Thanks. How do I set the value of amount to the value of another variable which is in a model called 'record' ? Like record.amt=amount

yes. you simply assign tht amount to another value. like self.field_name=amount.

관련 게시물 답글 화면 활동
2
3월 23
9108
2
3월 23
1674
2
5월 22
3726
0
3월 22
1207
1
5월 21
3763