تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
4121 أدوات العرض

i want to show for every value of a selection field a certain forme of sequence 

here is my code 

def generate_budget_no(self):
        if self.sequence == 'New':
            if self.type_bdg == 'hit':
                self.sequence = self.env['ir.sequence'].next_by_code('seq.hit')
            if self.type_bdg == 'dun':
                self.sequence = self.env['ir.sequence'].next_by_code('seq.dun')
            elif self.type_bdg == 'nv':
                self.sequence = self.env['ir.sequence'].next_by_code('seq.nv')
            return True


i have checked that sequences records are declared in the _manifest.py

but even when i click the button, it dosent generate the required sequence


الصورة الرمزية
إهمال

You have to call this in create method and use vals parameter to check the value of the type_bdg and sequence because the self not have the value of the field yet.

def create(self,vals):

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

type_bdg = vals.get('type_bdg', False)

if type_bdg == 'hit':

vals['sequence'] = self.env['ir.sequence'].next_by_code('seq.hit')

if type_bdg == 'dun':

vals['sequence'] = self.env['ir.sequence'].next_by_code('seq.dun')

elif type_bdg == 'nv':

vals['sequence'] = self.env['ir.sequence'].next_by_code('seq.nv')

return super([YourModelName], self).create(vals)

Hello,

I would suggest logging the variables "self.sequence" and "self.type_bdg", to make sure the values are what you are expecting.

Could you supply extra code linking to, what I assume is a selection field, char field and where you are calling the generate_budget_no function from.

Thanks,

الكاتب

class BudgetBudget(models.Model):

_inherit = 'budget.budget'

sequence = fields.Char(string='Sequence', readonly="1")

type_bdg = fields.Selection([('hit', 'HIT'), ('dun', 'Dun'), ('nv', 'NV')], default='nv', string='Type')

def create(self,vals):

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

type_bdg = vals.get('type_bdg', False)

if type_bdg == 'hit':

vals['sequence'] = self.env['ir.sequence'].next_by_code('seq.hit')

if type_bdg == 'dun':

vals['sequence'] = self.env['ir.sequence'].next_by_code('seq.dun')

elif type_bdg == 'nv':

vals['sequence'] = self.env['ir.sequence'].next_by_code('seq.nv')

return super(BudgetBudget, self).create(vals)

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

<field name="name">BSH</field>

<field name="code">seq.hit</field>

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

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

</record>

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

<field name="name">BSD</field>

<field name="code">seq.dun</field>

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

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

</record>

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

<field name="name">BSN</field>

<field name="code">seq.nv</field>

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

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

</record>

here is my code

الكاتب أفضل إجابة

i just tried your code, but still got nothing, 

i've also correct the first if statment, sequence istead of name 

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


الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
ديسمبر 22
2509
2
مايو 20
4574
4
مايو 24
12747
1
أبريل 24
3360
0
نوفمبر 23
2062