This question has been flagged
2 Replies
68339 Views

I go this following error when I click a button on my custom addons:


Error:
Odoo Server Error
Traceback (most recent call last):
  File "/opt/odoo/odoo12/odoo/http.py", line 656, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo12/odoo/http.py", line 314, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/opt/odoo/odoo12/odoo/tools/pycompat.py", line 87, in reraise
    raise value
  File "/opt/odoo/odoo12/odoo/http.py", line 698, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo12/odoo/http.py", line 346, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo12/odoo/service/model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo12/odoo/http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo12/odoo/http.py", line 941, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo12/odoo/http.py", line 519, in response_wrap
    response = f(*args, **kw)
TypeError: load() missing 1 required positional argument: 'action_id'


But not sure from where that following error source since the error log does not refer to any of my customs addons.


So, what should I fix for this..?


UPDATE: Add code.

Here is my models.py

from odoo import api, fields, models, _
import time
from odoo.exceptions import UserError
import logging

_logger = logging.getLogger(__name__)


class invoice(models.Model):
_name = 'account.invoice'
_inherit = 'account.invoice'

printer_data = fields.Text(string="Printer Data", required=False)

@api.multi
def generate_printer_data(self):
tpl = self.env['mail.template'].search([('name', '=', 'Dot Matrix Invoice')])
data = tpl._render_template(tpl.body_html, 'account.invoice', self.id, post_process=False)
self.printer_data = data

@api.multi
def action_invoice_cancel(self):
self.printer_data = ''
return super(invoice, self).action_cancel()

@api.multi
def action_invoice_open(self):
res = super(invoice, self).action_invoice_open()
self.generate_printer_data()
return res


And here is my invoice.xml where the button I click got that error.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_dotmatrix_invoice" model="ir.ui.view">
<field name="name">view_dotmatrix_invoice</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<header position="inside">
                # I got error when I click this button bellow
<button type="action" string="Dot Matrix" icon="fa-print" custom="print"/>
</header>

<notebook position="inside">
<page string="Dot Matrix">
<button string="Refresh Printer Data" icon="fa-print" states="open" type="object" name="generate_printer_data"/>
<pre>
<field name="printer_data"/>
</pre>
</page>
</notebook>
</field>
</record>
</odoo>




and here is the print_button.js

odoo.define('vit_dotmatrix.print_button', function (require) {
'use strict';

var form_widget = require('web.form_widgets');
var core = require('web.core');

var QWeb = core.qweb;
var _t = core._t;


form_widget.WidgetButton.include({
on_click: function() {
if(this.node.attrs.custom === "print" ){
console.log("print triggered");
var url = "http://localhost/dotmatrix/print.php";

var view = this.getParent();
var printer_data = view.datarecord.printer_data;
if (!printer_data){
alert('No data to print. Please click Update Printer Data');
return;
}
// code ajax printer
console.log(printer_data);

$.ajax({
method : "POST",
url: url,
data: {
printer_data: printer_data
},
success: function(data){
console.log('Success');
console.log(data);
},
error: function(data){
console.log('Failed');
console.log(data);
},
});
}
else{
this._super();
}
}
});
});


That is three related code from my addons.

Avatar
Discard
Best Answer

Hi,

The reason of this error is function might be expecting three arguments and you might be called the same function with only two arguments, where the function is expected to call with three arguments, in this case you will get such an error message.


So in your case if you are getting error on clicking the custom button, check the code and corresponding function of the button and see. Or update the question with the necessary code that you have added for the button.


UPDT:

You haven't specified the action to the button, that's why you get the error, you have given the button type as action, so using the name you have to specify which action to execute.


Sample:

<button type="action"
name="%(mrp.action_change_production_qty)d"
string="Update" states="confirmed,planned,progress" class="oe_link"/>

Button Types in Odoo: https://www.youtube.com/watch?v=_aCRtK0xOpQ

Thanks

Avatar
Discard
Author

Hi, thanks for this response, I have updated my questions.

Look forward to your next response :)

See the updated answer