Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
4741 Ansichten

I added two float fields (previous_count and current_count) to account.move.line. What I want to achieve is to set the value of quantity to current_count - previous_count. This works the way I want it to, however, when I save the invoice, the value of current_count and previous_count  is reset to zero, instead of maintaining  the value I entered. But  the value of quantity is saved

This is my code

class AccountMoveLine(models.Model):
    _inherit = "account.move.line"

    previous_count = fields.Float(string='Previous Reading')
    current_count = fields.Float(string='Current Reading')

@api.onchange('current_count')
    def _onchange_current_count(self):
        for line in self:
            line.quantity = line.current_count - line.previous_count
   

I have read several articles about overriding the create/write methods. I tried to do that, but it still wasn't working.  How can I get the value of current_value and previous_value to be saved?  

Thanks for any help given...

Avatar
Verwerfen
Beste Antwort

Hi,

Is those fields are read only fields , if so add force_save attribute and try. If there are not read only fields, and if you added the new fields only in the invoice_lines_ids one2many field(Page: Invoice Lines) , add the same under line_ids one2many fields(Page: Journal Items)  in the same view and see.


Thanks

Avatar
Verwerfen
Autor

Thanks a lot Niyas. The solution was in adding the fields to the line_ids field.

Great, any explanation of why it's required to add that field in Journal Items. I

Thanks Niyas, You saved my day! My module was finished until I noticed that all the was gone after I saved. Adding force_save="1" did the trick.

Fantastic .. but why this behavior is like that ?

Thank you, Niyas

Thanks Niyas, and to respond to Muhammad and Husam:
From v13, the invoice line records are now account.move.line records, and the invoice_line_ids (Invoice Lines tab) tree view in the form only shows a subset of all the account.move.lines (the ones with exclude_from_invoice_tab = False).
The line_ids (Journal Items tab) tree view shows all the account.move.lines (including those that wouldn't normally appear on an invoice), so that makes it the definitive form that gets saved.
You will need to add any invisible fields to line_ids as well, and don't forget to update the additional <form> element within the invoice_line_ids <field> element to show values in 'detail' view and when editing on a mobile device.

Beste Antwort

Thank you, Niyas

Avatar
Verwerfen