Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
2834 Представления

I'm trying to create a sequense the prefix of sequence based on another field named country_of_origin , but it doesn't work
The code:




Item Sequence
product.template.sequence

5




python code:

class ProductTemplate(models.Model):
_inherit = 'product.template'country_of_origin=fields.Char(string="Origin Country")
automatic_item_number=fields.Char(string="Item Number")

@api.model
def create
(self,vals_list):
#vals_list['admission_code']=self.env['ir.sequence'].next_by_code('product.tempate.sequence')
vals_list['automatic_item_number']=self.env['ir.sequence'].next_by_code('product.template.sequence')
result = super(ProductTemplate, self).create(vals_list)
print(self.automatic_item_number)
return result



Аватар
Отменить
Лучший ответ

Hi, 

There’s a mistake in what you have done in the above codes. You are creating a record in ir.sequence, but in field name=“prefix” , you are calling a field created in product.template.

One way to solve this is to remove the from the data file. And in the python file, try giving

vals_list['automatic_item_number']=self.country_of_origin + self.env['ir.sequence'].next_by_code('product.template.sequence')

Regards

Аватар
Отменить
Related Posts Ответы Просмотры Активность
0
окт. 24
2451
5
мар. 25
5735
2
апр. 24
2153
1
мар. 24
1187
2
мар. 24
1623