Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2546 Lượt xem

i want to create a sequence field in the res.partner model, from my custom module (my_module) 


for that i proceeded this way 

class ResPartner(models.Model):

    _inherit = 'res.partner'

account_number_is = fields.Char(string="Account Number")

@api.model def create(self, vals): if vals.get('account_number_is', ('New')) == ('New'): vals['account_number_is'] = self.env['ir.sequence'].next_by_code('acount.number.test') or ('New') result = super(ResPartner, self).create(vals) return result


and in the /data/sequence.xml i declared my sequence 

 <record id="seq_scanning_test" model="ir.sequence">
            <field name="name">Account Number Test</field>
            <field name="code">acount.number.test</field>
            <field name="prefix">Bq/</field>
            <field name="padding">4</field>
            <field name="company_id" eval="False"/>
        </record>

what i realize is that the create function dosent find the sequence because it isn't in the same model, so for that i tried this code 


@api.model 
    def create(self, vals):
        if vals.get('account_number_is', ('New')) == ('New'):
            vals['account_number_is'] = self.env['ir.sequence'].next_by_code('my_module.acount.number.test') or ('New')
        result = super(ResPartner, self).create(vals)
        return result 



but still dosent work yet, what i am still missing ? 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

The code in your first create method looks good to me. Just make sure you have added the sequence.xml file in the __manifest__.py file in the data section.

Ảnh đại diện
Huỷ bỏ
Tác giả

yes i had declared it in the __manifes__.py but the problem is i suppose is that the create methode dosent find the code refering to the sequence, because it dosent exists in the same model (res.partner), instead it is in my_module module

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 23
4165
2
thg 5 20
4619
4
thg 5 24
12821
1
thg 4 24
3436
0
thg 11 23
2083