Odoo Help

0
1 Answer
2
Avatar

NIKHIL KRISHNAN

--NIKHIL KRISHNAN--
--NIKHIL KRISHNAN--

-- Nikhilkrishnan --

Exploring new ways in odoo..!
And want to become a key to the new odoo trends.

-> Odoo Consultancy,
-> Functional and Technical Consultant,
-> Requirement Collection and Analysis,
-> Module Customization,
-> Odoo ERP Community Contributor,
-> Handling ERP/Odoo projects,
-> ERP Workshop Facilitator.
Feel happy working with best and good supporting team.

#PITS Family

Nikhil Krishnan

nikhilkrishnan0101@gmail.com

NIKHIL KRISHNAN
3/11/19, 7:37 AM

hi

Onchange fuction is not a good way, try this , it will help you.


class PurchaseOrderLine(models.Model):
    _inherit = 'purchase.order.line'
    @api.model
    def create(self, vals):
        if vals.get('product_qty') and vals['product_qty'] > 1:
            qty = int(vals['product_qty']) - 1
            print("VVVVV", vals)
            if qty:
                for q in range(qty):
                    vals['product_qty'] = 1
                    self.create(vals)
        res = super(PurchaseOrderLine, self).create(vals)
        return res

    @api.multi
    def write(self, vals):
        if vals.get('product_qty') and vals['product_qty'] > 1:
            qty = int(vals['product_qty']) - 1
            if qty:
                for q in range(qty):
                    vals = {'product_id': self.product_id.id,
                            'product_qty': 1,
                            'name': self.name,
                            'date_planned': self.date_planned,
                            'price_unit': self.price_unit,
                            'product_uom': self.product_uom.id,
                            'order_id': self.order_id.id,
                            }
                    self.create(vals)
        res = super(PurchaseOrderLine, self).write(vals)
        return res

If you have any further questions, please do not hesitate to comment.

Regards,
Nikhilkrishnan

Ask a Question
Writer
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