Odoo Help

Welcome!

This community 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.

0

How to create a custom field that incremental increase its value only to stockables products?

By
James Ford
on 2/24/16, 9:21 AM 366 views

Hello, I created a custom field in the odoo GUI. A field assigned a sequence.The idea is that incremental increase its field single value when selecting a product of stockable type . CUSTOM FIELD NAME = 'x_niu'

At the view I generated the sequence , but for all products , not just for stockables products:

Image: http://en.zimagez.com/zimage/werfwrwerwerwer.php

I have created a method to allocate the sequence but not the custom field validation is performed : product.type =='product'         (stockable product).

_defaults = {

    'x_niu':lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'sale.order.line'),

}

def create(self, cr, uid, vals, context=None):

    if vals.get('x_niu') == None and product_id.type == 'product':

        vals['x_niu'] = self.pool.get('ir.sequence').get(cr, uid, 'sale.order.line')

    return super(SaleOrderLine,self).create(cr, uid, vals, context)


def copy (self, cr, uid, id, default=None, context=None):

    default.update({

         'x_niu': self.pool.get('ir.sequence').get(cr, uid, 'sale.order.line')

    })

    return super(res_partner, self).copy(cr, uid, id, default, context)

I hope you can help me with this problem is not how to solve it . Thanks so much.

0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 2/25/16, 2:09 AM

Hello,

Try to remove the _defaults dict. Because this will call the sequence every time a new record created without checking the product type.


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/24/16, 9:21 AM
Seen: 366 times
Last updated: 2/25/16, 2:09 AM