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 add data to the Total Amount in Sales Quotation

By
Jayson Wu
on 6/3/14, 5:30 AM 1,780 views

Hi,

I'm trying to add 2 more fields on "Sales Quotation" (Shipping and Bank Charges). I'm done with adding the said fields to the form. Now, my problem is, my float fields are not recognized by the function that I created which would add everything up (Total Amount + Shipping + Bank Charges). I've tried adding a number to the Total Amount function and it successfully adds that number.

Here are my codes:

sales_quotation.py

from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
import time
from openerp import pooler
from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare
import openerp.addons.decimal_precision as dp
from openerp import netsvc

class sale_order(osv.osv):

    def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
        res = super(sale_order, self)._amount_all(cr, uid, ids, field_name, arg, context)
        for order in self.browse(cr, uid, ids, context=context):
            res[order.id]['amount_total'] += 0 **If I tried to replace 0 with a number it adds up, but if I use res[order.id]['banks'] or res[order.id]['shiping'] it won't add up.**
        return res
    
    def _get_order(self, cr, uid, ids, context=None):
        result = {}
        for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context):
            result[line.order_id.id] = True
        return result.keys()
        
    _inherit = 'sale.order'
    _columns = {
        'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Sale Price'), string= 'Total', store= {'sale.order.line': (_get_order, None, 10),}, multi= "sums", help= "The total amount"),
        'amount_untaxed': fields.function(_amount_all, digits_compute= dp.get_precision('Sale Price'), string='Untaxed Amount', store= {'sale.order.line': (_get_order, None, 10),}, multi= "sums", help="The amount without tax"),
        'shiping': fields.float('Shiping'),
        'banks': fields.float('Banking'),
    }
sale_order()

sales_quotation_view.xml

<openerp>
    <data>
        <record model="ir.ui.view" id="view_order_form2_inherit">
            <field name="name">sale.order.inherit2</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                    <field name="amount_untaxed" position="before">
                        <group class="oe_subtotal_footer oe_right" colspan="2" name="custom_added">
                            <field name="shiping" widget="monetary" options="{'currency_field': 'currency_id'}"/>
                            <field name="banks" widget="monetary" options="{'currency_field': 'currency_id'}"/>
                        </group>
                    </field>
            </field>
        </record>
    </data>
</openerp>

Thanks!

 

Edit:

I also tried to change the fields Shiping and Banks from fields.float().

        'shiping': fields.function(_amount_all, digits_compute= dp.get_precision('Sale Price'), string='Untaxed Amount', store= {'sale.order.line': (_get_order, None, 10),}, multi= "sums", help="The shipping charge"),

        'banks': fields.function(_amount_all, digits_compute= dp.get_precision('Sale Price'), string='Untaxed Amount', store= {'sale.order.line': (_get_order, None, 10),}, multi= "sums", help="The bank charge amount"),

and replace the computation by:

res[order.id]['amount_total'] += res[order.id]['shiping'] + res[order.id]['banks']

and since if we change the field.float to fields.function the field becomes read only so I added readonly="0" to the xml view.

The shiping and banks are now adding up to the amount total, however, if I apply changes to the shiping and banks, it is not registering (so only the first value of shiping and banks are the ones who are added to the amount total) .

@prakash Hi I tried your code, but it is still not adding. Unfortunately, there are no error messages.

Jayson Wu
on 6/3/14, 6:00 AM

@prakash, it is now adding. However, I can only do it once. If I typed another value to the boxes, and pressed udpate, it will not change.

Jayson Wu
on 6/5/14, 10:28 PM
1

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 6/3/14, 5:45 AM

Try the below code:-

 

 def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
        res = super(sale_order, self)._amount_all(cr, uid, ids, field_name, arg, context)
        for order in self.browse(cr, uid, ids, context=context):
            res[order.id]['amount_total'] += order.amount_total + order.banks + order.shipping
        return res

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: 6/3/14, 5:30 AM
Seen: 1780 times
Last updated: 9/14/15, 1:59 PM