Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
8871 Visualizzazioni
<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)
Avatar
Abbandona

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

Risposta migliore

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

Avatar
Abbandona
Risposta migliore

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.


Avatar
Abbandona