İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
1196 Görünümler

Odoo v18.0 has new view on inovice form.

invoice_currency_rate field is readonly=True.

When i make it readonly=False and change the rate and save, the value recompute.

I want to set the value and save it as is.

But insertation process runs precompute attiributes.

 

account move py:

invoice_currency_rate = fields.Float(        

​string='Currency Rate',        compute='_compute_invoice_currency_rate', store=True, ​ ​precompute=True,        copy=False,        digits=0,        help="Currency rate from company ​currency to document currency.",    

​)

 

Is it possible to change this?

Any ideas? 

Avatar
Vazgeç
Üretici

Thank you very much Rakesh.

En İyi Yanıt
  1. Remove precompute=True:
    • In account_move.py, remove or comment out the precompute=True attribute on invoice_currency_rate. This will stop it from precomputing the value.
    pythonCopy codeinvoice_currency_rate = fields.Float(
        string='Currency Rate',
        compute='_compute_invoice_currency_rate',  # keep the compute method if you need it for initial computation
        store=True,
        copy=False,
        digits=0,
        help="Currency rate from company currency to document currency.",
    )
    
  2. Add a Condition in the Compute Method:
    • If you still want to use the compute method but only when necessary, modify _compute_invoice_currency_rate to check if a value is manually set and only compute if it’s not set. For instance:
    pythonCopy code@api.depends('currency_id', 'company_id')
    def _compute_invoice_currency_rate(self):
        for record in self:
            if not record.invoice_currency_rate:
                # Add logic to compute the rate only if it's empty
                record.invoice_currency_rate = self._get_currency_rate()
    
  3. Make the Field Editable in the Form View:
    • Update the form view XML to make invoice_currency_rate visible and editable by removing the invisible attribute or setting it to False:
    xmlCopy code<field name="invoice_currency_rate" attrs="{'invisible': False}"/>
    

With these changes, invoice_currency_rate should remain editable, allowing you to set the rate manually without it recomputing on save. Make sure to test thoroughly to ensure that other dependencies on this field’s value work as expected.

PLEASE TRY THIS OTHERWISE I FIND AN ALTERNATE SOLUTION 

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Haz 25
1205
3
Mar 25
2151
2
Şub 25
5224
1
Şub 25
1937
1
May 25
1362