Odoo Help

0

0
1 Answer
3
Anagh Jose India
8/14/19, 3:30 AM


If you want to just add 2 new fields to the existing sale order line model, you do not have to use  the line 

_name = 'cave.vente'

this line would treat the newly declared class as a new table in Odoo. ie a new table named cave.vente will be created and the all fields of sale order.line and additional two new  fields that you wanted to create will be added to this table and this table would stay as a separate table. this is not the right usage. the right way to add two new fields to the sale.order.line table with your given code is as below.


class SaleOrderLine(models.Model): 
    _inherits = 'sale.order.line' 

    @api.model 
    def _calcul_qt_vendu(self): 
​        qty = 0 
        for rec in self: 
            qty= rec.qte_sortie - rec.qte_retournee 
            rec.update({'product_uom_qty': qty})


     qte_sortie = fields.Integer('Quantité chargée') 
     qte_retournee = fields.Integer('Quantité retournée') 
     product_uom_qty = fields.Integer('Quantité commandée', compute='_calcul_qt_vendu', store=True, readonly=True)


############################################

Now after writing this code, in order to make these fields visible in the sale order  form view , you will need to inherit the sale order xml view definition and using xpath statement, you will need to put these fields in sale order line.


 


Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now