Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
9146 Lượt xem
<record id="product_code_sequence" model="ir.sequence">
<field name='name'>Code Sequence </field>
<field name="code">product_code_new</field>
<field name="prefix"> %(code)</field> %%%%not workig this code
<field name='padding'>3</field>

</record>
@api.model
def create(self,vals):
category=vals['categ_id']
categ_name=self.env['product.category'].browse(category)
name_details=str(categ_name.name)[:3]
product_name=str(vals['name'][:3])
code=product_name+name_details#######this field i want to add prefix in xml
vals.update({
'product_code':self.env['ir.sequence'].next_by_code('product_code_new')})
return super(ProductTemplate,self).create(vals)
Ảnh đại diện
Huỷ bỏ

Hello, have you found the way to do that?
thanks

Câu trả lời hay nhất

Hi,

You can inherit the compute function( if there any or else add a new compute function) and add some condition for specifying the name as below.

@api.depends('variable', 'operator', 'max_value', 'list_base_price', 'list_price', 'variable_factor')
def _compute_name(self):
    for rule in self:
        name = 'if %s %s %.02f then' % (rule.variable, rule.operator, rule.max_value)
        if rule.list_base_price and not rule.list_price:
            name = '%s fixed price %.02f' % (name, rule.list_base_price)
        elif rule.list_price and not rule.list_base_price:
            name = '%s %.02f times %s' % (name, rule.list_price, rule.variable_factor)
        else:
            name = '%s fixed price %.02f plus %.02f times %s' % (name, rule.list_base_price, rule.list_price, rule.variable_factor)
        rule.name = name

Regards

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

you can simply do this:

on the XML:

<field name="prefix">ANY_KEY_WILL_DO</field> <!--- this will work -->




on Python:
product_code = self.env['ir.sequence'].next_by_code('product_code_new')
product_code = product_code.replace("ANY_KEY_WILL_DO", code)
vals["product_code"] = product_code


i know the question is long time ago, but hope it helps someone else in the future. thanks.


Ảnh đại diện
Huỷ bỏ