Skip to Content
Menu
This question has been flagged

I have inherited pos.order model adding some extra fields and my definitions via custom module:

class PosOrderDV(models.Model):
_inherit = "pos.order"
 
profit = fields.Float('Lucro', store=True, index=True, digits=(5,2))
costs = fields.Float('Custos', store=True, index=True, digits=(5,2))

    @api.multi 
  def cost_elab(self):
    ### do stuff ###

Odoo has his personal way to interact with fields trough definition, and I'm seeing a lack of good docs to archive that. Perhaps is better stay with my daemon, but I'm curious to know how people are managing the conversion.

For now, all I got were a series of errors, the most common are

ValueError: <type 'exceptions.AttributeError'>: "'pos.order' object has no attribute 'cost_elab'"

if I call my def with env['pos.order'].cost_elab()

or

NameError: name 'self' is not defined

if I use self.env['pos.order'].cost_elab()




Avatar
Discard
Best Answer

Hi,

check whether your object is browsable, and you can call function by

env['pos.order'].cost_elab() like self.env['product.uom']._compute_price(line.product_id.uom_id.id, purchase_price, to_uom_id=line.product_uom.id)


class x(Object):

     def y():

         return "teste"

class y(models.Model, x):

     """ here I can access function y as self.y() """

     print self.y()

if still probs, then please give me your example code

In case of odoo lets take an example.


class res_partner(models.Model):
_inherit = "res.partner"
    @api.multi
def google_map_img(zoom=17, width=298, height=298):
partner = self.browse([partner_id])
        params = {
  'center': '%s, %s %s, %s' % (partner.street or '',
        partner.city or '',
        partner.zip or '',
        partner.country_id and partner.country_id.name_get()[0][1] or ''),
        'size': "%sx%s" % (height, width),
  'zoom': zoom,
        'maptype': 'hybrid',
  'sensor': 'false',
  }
        return urlplus('//maps.googleapis.com/maps/api/staticmap', params)

class test(models.Model):
     _name = 'your.name'

     @api.multi
     def test(self):
partner = self.sudo().partner_id
    return partner and partner.google_map_img(zoom, width, height) or None

In case you have no record set try @api.model instead of multi



     

Avatar
Discard
Author

Can you please elaborate more?

In pure python with the help of psycopg2 is quite easy trigger an action (I'm using a daemon now) but the more I dig into Odoo the more I realize perhaps is better stay with my own setup.

If you think is important I'll update the OP with a draft of my python code.

Author

And just for let you know, your example give me an error of invalid syntax after 'like'.

like is not an operator here , i just used to explain an example.

eg: self.env['product.uom']._compute_price(line.product_id.uom_id.id,purchase_price,to_uom_id=line.product_uom.id)

Author

Ok, I'll have a look more deeply using your sample code.

But somehow 'self' doesn't works well with pos.order/server action.

See my previous thread here:

https://www.odoo.com/forum/help-1/question/solved-server-actions-how-to-replace-self-write-command-with-new-api-for-odoo-10-113549

I see try @api.model instead of @api.multi

Author

Hilar, thank you for your time.

I prefer not to use @api.model, since I would like to use just the new API.

Let me assimilate the concept and Í'll write some lines of code. But again, coding under Odoo should be more simple... Or probably I'm just getting old!

Related Posts Replies Views Activity
9
Dec 17
13779
2
Feb 17
4700
1
Feb 18
4302
0
Feb 17
5
2
Nov 24
25067