Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
15 Trả lời
6967 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ

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?

Tác giả

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 !

Tác giả Câu trả lời hay nhất

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

}





Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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')
Ảnh đại diện
Huỷ bỏ
Tác giả

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

Tác giả

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

Tác giả

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 !

Tác giả

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?

Tác giả

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.

Tác giả

Yes, Juan, I did it

Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

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 !

Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 5 16
4730
1
thg 1 24
2113
1
thg 12 22
3315
1
thg 10 24
25664
2
thg 8 21
2974