<record id="product_code_sequence" model="ir.sequence">@api.model
<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>
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)
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Comptabilité
- Inventaire
- PoS
- Project
- MRP
Cette question a été signalée
2
Réponses
9013
Vues
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
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.
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !
Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !
S'inscrire
Hello, have you found the way to do that?
thanks