Skip to Content
Menu
This question has been flagged
15 Replies
5793 Views

Hello,


I tried differents things but my problem is that I don't know how to edit one field in the order form of point of sale. I'm currently using Odoo 9.

You can see the field, in the red circle, here :

http://i.imgur.com/DjEYJiS.png

Maybe, the changes to do are in a python or javascript file.


Please, help me.


Thanks.

Avatar
Discard

search for the text 'def _amount_all_wrapper' in sale module so you can see what this method do, then you need to override it creating a custom module. What kind of change do you want to make to the amount_total field?

Author

Hi Juan, Thank you for your help ! I searched in the sale module and I also did a "cat * | grep -R -e "_amount_all_wrapper" > /home/matthieu/result.txt but I didn't found it, it's why I'm asking for the file to find it. To answer your question, I did a custom module and I need to add to this value the value of the attribute "coupon_nb" from an inherit of pos_order from Point Of Sale. Thanks so much for your help !

Author Best Answer

Finally, it works.

My code is here :

class pos_order(osv.osv):

_name = 'pos.order'

_inherit = 'pos.order'

def _amount_all(self, cr, uid, ids, name, args, context=None):

res = super(pos_order, self)._amount_all(cr, uid, ids, name, args, context)

for order in self.browse(cr, uid, ids, context=context):

res[order.id]['amount_total'] += 42

return res

_columns = {

'amount_tax': fields.function(_amount_all, string='Taxes', digits=0, multi='all'),

'amount_total': fields.function(_amount_all, string='Total', digits=0, multi='all'),

'amount_paid': fields.function(_amount_all, string='Paid', states={'draft': [('readonly', False)]}, readonly=True, digits=0, multi='all'),

'amount_return': fields.function(_amount_all, string='Returned', digits=0, multi='all'),

}





Avatar
Discard
Best Answer

the field you are considering is the function/compute fields ,you can't change it value from front end , you can change it value only by overriding the _amount_all    method only.


@api.depends('order_line.price_total')
def _amount_all(self):
for order in self:
    amount_untaxed = amount_tax = 0.0
for line in order.order_line:
    amount_untaxed += line.price_subtotal
    amount_tax += line.price_tax
 order.update({
'amount_untaxed': order.pricelist_id.currency_id.round(amount_untaxed),
'amount_tax': order.pricelist_id.currency_id.round(amount_tax),
'amount_total': amount_untaxed + amount_tax,
 })

in odoo9 https://github.com/odoo/odoo/blob/9.0/addons/sale/sale.py#L24 


amount_total = fields.Monetary(string='Total', store=True, readonly=True, compute='_amount_all', track_visibility='always')
Avatar
Discard
Author

Thank you, but where is this method ? I've only found in point_of_sale.py : 'amount_total': fields.function(_amount_all, string='Total', digits=0, multi='all')

Hi Matthieu , i have update my answer above ,just open this link https://github.com/odoo/odoo/blob/9.0/addons/sale/sale.py#L24

Author

Ok, but my value is from an inherit of pos.order (https://github.com/odoo/odoo/blob/9.0/addons/point_of_sale/point_of_sale.py). So if I want to add it to amount_total of sale.py, how can I do ? Manythanks for your help !


On Wed, May 11, 2016 at 11:01 PM, Matthieu <matthieu.artaud@gmail.com> wrote:

Ok, but my value is from an inherit of pos.order (https://github.com/odoo/odoo/blob/9.0/addons/point_of_sale/point_of_sale.py). So if I want to add it to amount_total of sale.py, how can I do ? Manythanks for your help !

--
Matthieu

Sent by Odoo S.A. using Odoo

Author

Well, if this can really modify the field "Total" of orders, I think I didn't inherit it correctly. Here is my code : http://pastebin.com/1xF83Nt1 But the value is not changed at all :( Thanks a lot for all the answers !

Author

I tried differents things : -> I tried to directly edit the point_of_sale.py and I edited the line as it : res[order.id]['amount_total'] = res[order.id]['amount_tax'] + amount_untaxed + 42. The result was changed, so it was a sucess. -> I added a log in my function to see if it is executed. The log message was not written so I think the problem is that my function is not overriting the original one at all. I gonna try to see why, but if you find the problem, help me please !

Have you added the module name in the __openerp__.py file in depends tag?

Author

I have found the reason : the function name is _amount_all But the functions wich start with underscore (_) are private. So I can't inherit it.

Author

Yes, Juan, I did it

Best Answer

The function you need is in the sale module in file sale.py,

this is the code,

def _amount_all_wrapper(self, cr, uid, ids, field_name, arg, context=None):

""" Wrapper because of direct method passing as parameter for function fields """

return self._amount_all(cr, uid, ids, field_name, arg, context=context)

def _amount_all(self, cr, uid, ids, field_name, arg, context=None):

cur_obj = self.pool.get('res.currency')

res = {}

for order in self.browse(cr, uid, ids, context=context):

res[order.id] = {

'amount_untaxed': 0.0,

'amount_tax': 0.0,

'amount_total': 0.0,

}

val = val1 = 0.0

cur = order.pricelist_id.currency_id

for line in order.order_line:

val1 += line.price_subtotal

val += self._amount_line_tax(cr, uid, line, context=context)

res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val)

res[order.id]['amount_untaxed'] = cur_obj.round(cr, uid, cur, val1)

res[order.id]['amount_total'] = res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']

return res

just override the function  _amount_all  to change the price based on your coupon.

This functions are from v8.

Kind regards.

Avatar
Discard
Author

Thank you, this function doesn't exist anymore in Odoo 9 but I think _amount_all is the same, up to date. I'll try !

Related Posts Replies Views Activity
4
May 16
3758
1
Jan 24
490
1
Dec 22
2039
1
Oct 24
23253
2
Aug 21
1604