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

I am currently running Odoo v13 Community Edition. I am trying to make fields that show the converted value from USD or EUR to the currency of the Company (EGP)

I already have a Currency Rate field (currency_rate) that I can use to convert the currencies. The thing is the field called Unit Price in EGP (x_price_unit) sees the Currency Rate Field equal to zero.

Another problem I am facing is that the Currency Rate field is in the purchase.order model while the Unit Price in EGP field is in the purchase.order.line model and I do not know how I can compute Unit Price in EGP from that value. Below the image I added the code I've written to compute Unit Price in EGP.

Please guys help me if you can

Thank you in advance

Here is the code:

class PurchOrderLine(models.Model):

    _inherit = 'purchase.order.line'

    x_price_unit = fields.Float(readonly=True, compute="calc_unit_p", string='Unit Price in EGP', store=False)

    x_sub_tot = fields.Float(readonly=True, compute="calc_sub_t", string='Subtotal in EGP', store=False)


    @api.depends('price_unit')

    def calc_unit_p(self):

        for p in self:

            po = p.env['purchase.order'].search([])

            if po.currency_rate:

                p.x_price_unit = p.price_unit / po.currency_rate

            else:

                p.x_price_unit = p.price_unit

아바타
취소

There will be already a compute function for unit price calculation in lines. Why you are fetching all purchase orders? To achieve single record's computation, you will fetch 1000s of purchase orders?

작성자

I do not know how do I fetch the purchase order that belongs to the order line. Can you help me?

관련 게시물 답글 화면 활동
1
9월 21
7097
1
1월 23
6083
1
10월 20
4393
0
1월 24
1591
1
10월 20
4782