Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
1183 Widoki

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? 

Awatar
Odrzuć
Autor

Thank you very much Rakesh.

Najlepsza odpowiedź
  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 

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
cze 25
1203
3
mar 25
2151
2
lut 25
5202
1
lut 25
1926
1
maj 25
1357