Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1190 Vistas

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
Descartar
Autor

Thank you very much Rakesh.

Mejor respuesta
  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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jun 25
1204
3
mar 25
2151
2
feb 25
5210
1
feb 25
1929
1
may 25
1359