Se rendre au contenu
Menu
Cette question a été signalée

i'am added a method in product.template to compute the product name form strings of some custom fields that related to other models ,
 i added store=True to the name field so i can search about it , but when related fields change on their models the filed name dosn't change , so i need to add server action to menuitem called "update product name" which be located on cutome app that the related fields are there ,if i pressed on this menuitem it run the metode of naming and get new updated field on product name 
how can i do that 
here is the code 

class autopart(models.Model):
_inherit = 'product.template'

@api.multi
@api.depends('item','dsc', 'drc', 'org','car','model', 'manf','year')
def naming(self):
for rec in self:
if rec.year:
rec.name = " ".join(
[rec.item and rec.item.name or "", rec.drc and rec.drc.name or "", rec.dsc and rec.dsc.name or "",
rec.org and rec.org.name or "", rec.manf and rec.manf.name or "", rec.car and rec.car.name or "",
rec.model and rec.model.name or "",rec.year and rec.year.name or ""
])
else:
rec.name = " ".join(
[rec.item and rec.item.name or "", rec.drc and rec.drc.name or "", rec.dsc and rec.dsc.name or "",
rec.org and rec.org.name or "", rec.manf and rec.manf.name or "", rec.car and rec.car.name or "",
rec.model and rec.model.name or "",
])
name = fields.Char(string="Name", compute=naming ,store=True , required=False,)


<menuitem id="update_products_menu" name="Update products" parent="master.menu_category_main" sequence="1" action="action_update_products"/>

        <record id="action_update_products" model="ir.actions.server">
<field name="name">action_update_products</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_updateproducts"/>
<field name="state">code</field>
<field name="code">how can i run naming methode from product.template here</field>
</record>
Avatar
Ignorer
Meilleure réponse

 method call may done by :

        <record id="action_update_products" model="ir.actions.server">
<field name="name">action_update_products</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_updateproducts"/>
<field name="state">code</field>
<field name="code">action = records.naming()[//action name]</field> 
         </field>
        </record>

 

Avatar
Ignorer
Publications associées Réponses Vues Activité
0
mars 25
796
2
sept. 23
5765
1
avr. 23
3092
2
mars 23
2475
3
mars 22
9411