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 add a sequence a field?

By
James Ford
on 2/26/16, 6:29 AM 601 views

Hello, i've one doubt:

I created a field called ' niu ' to increase its value for each product type stockable.

niu = fields.Char(string="NIU", compute="_niu_validation", defalut=" ", readonly=True)

With the attribute compute = "_ niu_validation " I call the method of the same name . In this , I want to validate that the product type is stockable type .

@api.depends('product_id.product_tmpl_id.type')

def _niu_validation(self):

if 'product_id.product_tmpl_id.type' == 'product':

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

return super(SaleOrderLine,self)

<?xml version="1.0" encoding="utf-8"?>

<openerp>

<data noupdate="1">

On the other hand I created the render sequence for ' niu ' field in sale.order.line model.

<!-- Sequence for sale.order.line -->

<record id="seq_sale_order_line" model="ir.sequence">

<field name="name">NIU Sequence</field>

<field name="code">sale.order.line</field>

<field name="prefix">00</field>

<field name="padding">3</field>

</record>

</data>

</openerp>

And in the view , I want for each product type stockable, the field 'niu' increase its value.

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

Please I need help because I 've been a long time on this and I can't do it on my own. I hope your help , advice , recommendations. Thank you very much to all.

0

Jignesh Mehta

--Jignesh Mehta--
2081
| 6 4 8
Surat, India
--Jignesh Mehta--


Jignesh Mehta
On 3/2/16, 8:24 AM

Hello James,

Try Below field definition and code for create sequence automatically.


Field Definition :-

niu = fields.Char('NIU', readonly=True, select=True, copy=False, default='New')


Create Method :-

@api.model

def create(self, vals):

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

        vals['name'] = self.env['ir.sequence'].next_by_code('model.name') or 'New'

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

    return result


Hope it works for you.

Thanks,

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/26/16, 6:29 AM
Seen: 601 times
Last updated: 3/2/16, 8:24 AM