Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
2897 Näkymät

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

Avatar
Hylkää

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?

Tekijä

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

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
syysk. 21
6949
1
tammik. 23
5976
1
lokak. 20
4294
0
tammik. 24
1528
1
lokak. 20
4683