Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to edit Total value from order form

By
Matthieu
on 5/11/16, 5:50 AM 385 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.

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?

Juan Vicente Pascual
on 5/11/16, 10:29 AM

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 !

Matthieu
on 5/11/16, 10:53 AM
0
Matthieu
On 5/12/16, 9:41 AM

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'),

}





1

Prakash Sharma

--Prakash Sharma--
815
| 2 1 4
Delhi, India
--Prakash Sharma--

I like to surround myself with brave, creative people.

My motivation for learning different technologies and algos drive me. I love challenges of a steep learning curve which I believe makes me a better learner. I have a strong desire to learn different technologies, which would enable me to become a full stack developer.

Prakash Sharma
On 5/11/16, 10:03 AM

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')

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')

Matthieu
on 5/11/16, 10:11 AM

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

Prakash Sharma
on 5/11/16, 11:08 AM

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
on 5/11/16, 1:31 PM

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

Prakash Sharma
on 5/11/16, 2:31 PM

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 !

Matthieu
on 5/12/16, 3:19 AM

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 !

Matthieu
on 5/12/16, 5:09 AM

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

Juan Vicente Pascual
on 5/12/16, 7:02 AM

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.

Matthieu
on 5/12/16, 8:12 AM

Yes, Juan, I did it

Matthieu
on 5/12/16, 8:30 AM
0
Juan Vicente Pascual
On 5/11/16, 10:59 AM

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.

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 !

Matthieu
on 5/11/16, 1:26 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/11/16, 5:50 AM
Seen: 385 times
Last updated: 5/12/16, 9:43 AM