Ok, I was finally able to do what I wanted initially. I'll explain how now.
1: Always separate each type of object you might normally define inside views.xml
Normally you would code your standard objects on the views.xml file, but I strongly recommend you guys to always separate them, so you can call them from the mainfest in an order that doesn't compromise your module at the moment of its build into your Odoo server. Create a .xml for each type of action you are creating. (1 .xml for action.server, another for action.views and so). Create a .xml for each type of view, menu, etc you require.
2.Always use spaces for indentation, do not use TAB
I don't know why, but it was a pain to know the reason why some of the methods inside my models.py weren't being called was because I was using TAB instead of "spaces". I know it sounds illogical. But hear me out. If your method is not being recognizable by Odoo, check out you are using spaces instead of tabulation spaces.
3. If you want to do the same as me, here's my code for updating extended fields on 'account.invoice'
models.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
class YourClass(models.Model):
_inherit = 'account.invoice'
x_text_fld = fields.Text('attribute text1', default="default value")
x_boo_fld = fields.Boolean(default=False, string='attribute text2', readonly=True, help='define help here')
@api.multi
def x_method(self):
for rec in self:
self.x_boo_fld = True
self.x_text_fld = 'my custom text'
actionServer.xml (views.xml)
<odoo>
<data>
<recordmodel="ir.actions.server"id="x_cust_act">
<field name="name">myAction</field>
<fieldname="model_id"ref="account.model_account_invoice"/>
<fieldname="sequence">1</field>
<fieldname="type">ir.actions.server</field>
<fieldname="state">code</field>
<fieldname="code">
if records:
action = records.x_method()
</field>
</record>
</data>
</odoo>
Then on the button inside my formViews.xml: (views.xml)
<odoo>
<data>
<recordid="x_cust_frm_vw"model="ir.ui.view">
<fieldname="name">x_my_view</field>
<fieldname="model">account.invoice</field>
<fieldname="sequence"eval="16"/>
<fieldname= "arch"type = "xml">
<formstring="Invoice"class="o_invoice_form"create="false"edit="false">
<header>
<buttonname="%(x_cust_act)d"type="action"string="myButton"
attrs="{'invisible':['|',('sent','=',True), ('state', 'not in', ('open','paid'))]}"/>
<fieldname="state"widget="statusbar"nolabel="1"statusbar_visible="draft,open,paid"/>
</header> ...
</form>
</field>
</record>
</data>
</odoo>
Needless to say I did this button to be shown on a custom form view. I hope people can get a good example with my code. I tested it several times on clean Odoo instances and it works. So good luck.
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