Rui Vieira
Rui Vieira

Reputation: 23

Error on running python code with server action

I'm using odoo to develop an app which includes massive importation of data to a database. The procedure it's simple I created an object with char variables only so they can be equal to everything, thenIi read every line from an excel template for each line a new record for this object is created. Now I want to run a server action when all the excel lines where loaded, this way I can process every data, assign variables and choose a variable type for each column with another object I created. The problem is using server actions you can run a piece of code after the excel file is loaded with this line object.import_pricelist() but object, who is supposed to be a reference for my model it's a NoneType and has no method import_pricelist

Server Action Def.

<record id="action_python_import" model="ir.actions.server">
    <field name="name">Import PriceList</field>
    <field name="model_id" ref="model_product_raw"/>
    <field name="condition">True</field>
    <field name="type">ir.actions.server</field>
    <field name="state">code</field>
    <field name="code">object.import_pricelist()</field>
</record>

Model and Method def

class ProductRaw(models.Model):
_name="product.raw"

name = fields.Char("Product Name")
price = fields.Char("Product Price")
vendor_code = fields.Char("Vendor Code")
product_code = fields.Char("Product Code")
flag_processed = fields.Boolean("Processed",default=False)
flag_error = fields.Boolean("Error",default=False)
error_desc = fields.Char("Error Description")

@api.multi
def import_pricelist(self):

Upvotes: 1

Views: 489

Answers (1)

self should be a reference to your model, object is a reference to active_id, if provided in the context. If you are trying to run a method that is not connected to any particular object of the model (you want to create objects if I understand you correctly), than you should use @api.model decorator instead of @api.multi, and self instead of object, like this:

    <field name="code">self.import_pricelist()</field>

Please let me know if I helped.

Upvotes: 1

Related Questions