1
votes

I have an action like so:

. . .
<record id="confirm_action" model="ir.actions.server">
<field name="name">Confirm</field>
<field name="binding_model_id" ref="my_module.model_purchase_order_line"/>
<field name="model_id" ref="my_module.model_purchase_order_line"/>
<field name="state">code</field>
<field name="code">
  action = records.confirm_line()
</field>
</record>
. . .

and I have this code in my model:

class purchase_order_line_inherit(models.Model):
_inherit = "purchase.order.line"

def confirm_line(self):
    for line in self:
        purchase_orders = self.env['purchase.order.line'].search(['product_id.id','=',line.product_id.id])

Here is the error:

Odoo Server Error Traceback (most recent call last): File "/home/odoo/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch result = request.dispatch() File "/home/odoo/odoo/odoo/http.py", line 683, in dispatch result = self._call_function(**self.params) File "/home/odoo/odoo/odoo/http.py", line 359, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/odoo/odoo/odoo/service/model.py", line 94, in wrapper return f(dbname, *args, **kwargs) File "/home/odoo/odoo/odoo/http.py", line 347, in checked_call result = self.endpoint(*a, **kw) File "/home/odoo/odoo/odoo/http.py", line 912, in call return self.method(*args, **kw) File "/home/odoo/odoo/odoo/http.py", line 531, in response_wrap response = f(*args, **kw) File "/home/odoo/odoo/addons/web/controllers/main.py", line 1733, in run result = action.run() File "/home/odoo/odoo/odoo/addons/base/models/ir_actions.py", line 629, in run res = runner(run_self, eval_context=eval_context) File "/home/odoo/odoo/odoo/addons/base/models/ir_actions.py", line 498, in _run_action_code_multi safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True) # nocopy allows to return 'action' File "/home/odoo/odoo/odoo/tools/safe_eval.py", line 346, in safe_eval raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr)) Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/odoo/odoo/odoo/http.py", line 639, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/odoo/odoo/odoo/http.py", line 315, in _handle_exception raise exception.with_traceback(None) from new_cause ValueError: <class 'TypeError'>: "'int' object is not subscriptable" while evaluating 'action = records.confirm_line()'

What I want to do is just to get data of purchase order lines that has the same product as the line I selected before. What did I do wrong?

It is giving me the error from this line purchase_orders = self.env['purchase.order.line'].search(['product_id.id','=',line.product_id.id]).

1

1 Answers

2
votes

The last code part seems wrong in some ways. Firstly you won't get orders but order lines. So rename the variable purchase_orders. And secondly you don't need the .id in the domain left part. And thirdly the domain has a wrong syntax, because a domain has to be a list of special logic operators and/or 3-tuples. But right now it is a list of 2 strings and an integer.

So finally the method should look like:

def confirm_line(self):
    for line in self:
        purchase_order_lines = self.search([('product_id','=',line.product_id.id)])
        # here something has to be done, because right now
        # nothing will happen at all