I want to code a server action for updating some custom (extended) field on account.invoice (Odoo11)
My custom fields are a boolean and a text(string).
So far until now, i have found and adapted this
<!---->
<record model="ir.actions.server" id="my_act_serv_id">
<field name="name">My action Name</field>
<field name="model_id" ref="model_account_invoice"/>
<field name="state">code</field>
<field name="code">
action = {}
</field>
</record>
Now i don't understand how to update my extended fields. I guess I should put python code inside "action{}" but will it be enough to write
action={[('my_custom_boolean', '=', True), ('my_custom_text','=','action_response_text')]}How do I call and write my extended fields?
I would very much appreciate any info relevant to this, since on the documentation i found definition for method but very few examples on how to execute them.
Would you also kindly not tell me to do this by Odoo developer tools? I would like to do this by code. Thanks in advance.
Here's the complete code if you feel like forking it. I currently have it at this level
views.xml
<record model="ir.actions.server" id="x_nc_act_serv_fact">
<field name="name">Enviar Factura</field>
<field name="model_id" ref="model_account_invoice"/>
<field name="sequence">1</field>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">
action = self.x_nc_met_fac()
</field>
</record>
models.py
from odoo import models, fields, api, _
class myclasscust(models.Model):
_inherit = 'account.invoice'
x_nc_fld_det_fact = fields.Text('Detalle Enviado', default="Envío pendiente")
x_nc_fld_fact = fields.Boolean(default=False,
string='Enviado',
readonly=True,
help='help')
@api.multi
def x_nc_met_fac(self):
self.x_nc_fld_fact = True
self.x_nc_fld_det_fact = 'Factura homologada'
This code generates a new server action. But it does nothing. So i guess the framework of the server action is correct, but the code inside it is not.
I am trying to call it from a button and testing it by type=object and type=action. None of them seem to make the action work.
With the button type=action it returns nothing, but with type=object Odoo returns the following error:
File "/usr/lib/python3/dist-packages/odoo/api.py", line 685, in call_kw
method = getattr(type(model), name)
AttributeError: type object 'account.invoice' has no attribute 'Enviar Factura'
Get an idea of server action: http://learnopenerp.blogspot.com/2020/01/odoo-server-action.html