Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
10057 มุมมอง

Hi guys


Im trying to override odoo 9 sale.order create method, so that only products belonging to the same category can be sold:

    from openerp import api

    from openerp.osv import fields, osv

    import vatnumber

    from openerp.tools.translate import _

    from openerp.exceptions import UserError, ValidationError

    class sale_order(osv.osv):

        _inherit = "sale.order"

       @api.model

       def create(self, vals):

           product_ids=[]

           product_categ_ids=[]

           if vals.get('name', 'New') == 'New':

               if vals.get('order_line'):

                   order_lines_vals=vals['order_line']

                   for l in order_lines_vals:

                       for value in l:

                           if isinstance(value, dict):

                               product_ids.append(value['product_id'])

               if product_ids:

                   for j in self.env['product.product'].browse(product_ids):

                       product_categ_ids.append(j.product_tmpl_id.categ_id.id)

                   product_categ_ids=list(set(product_categ_ids))

                   if len(product_categ_ids) > 1:

                       raise ValidationError(_("Is not possible to add products belonging to more than one category!"))

       result = super(SaleOrder, self).create(vals)

       return result




Everything works fine except the error, record is not created but no popup window error is displayed,,,,,does anyone know how to handle correctly with exceptions in odoo 9?


Thanks in advance

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Diego Calzadilla,

First of all you are inherited sale order in v7 style.

for v9 you have to inherit as following:

     class SaleOrder(models.Model):

         _name = 'sale.order'


Here your code seems fine except that super call, in super call you have to mention class name.

so as per your code, super call must be like

    super(sale_order, self).create(vals)

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 24
6645
3
ส.ค. 24
7441
how to know the odoo master password? แก้ไขแล้ว
4
ก.ค. 24
42214
0
เม.ย. 24
2652
Default value in form view แก้ไขแล้ว
5
เม.ย. 23
100442