Skip to Content
Menu
This question has been flagged
1 Reply
7806 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) .

Avatar
Discard
Author

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

Author

@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.

Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 20
3736
1
Jul 23
1273
6
Apr 23
31739
2
Dec 23
11088
3
Jul 22
20959