ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

How to Override py method in erpnext v9


#1

Hello All,

I am trying to override py method named “calculate_item_values” is available in (erpnext=>erpnext=>controllers=>taxes_and_totals.py) erpnext
to do a calculation for an amount in sales order lines.

Below is my code, I added in my custom application by creating controllers directory but it not working.
(Path : my_custom_app=>my_custom_app=>controllers=>taxes_and_totals.py)

from frappe.utils import flt
from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals
print "\n :::My Custom App Call ::::::::::"

class CalculateTaxesAndTotals(calculate_taxes_and_totals):
def calculate_item_values(self):
print "\n :::::My Custom App Method Call ::::::::::"

Please help me on this.

Thanks in advance. :slight_smile:


#2

Overriding individual method is not easily possible. What are you trying to achieve? (use case)?


#3

Hello @rmehta,

Thank you for valuable reply.
I need to change some calculation for amount in sales order items.
I need to calculate amount (rate*stock_qty).
item.amount = flt(item.rate * item.stock_qty, precision(“amount”, item));

Thanks


#4

Hello All,
I really need this. anyone have an idea about it? how can I do?
Thanks in advance.


#5

Amount is already calculated in item, right?


#6

Hello,

Yes, Amount is calculated in Sale Order Item.
Now, Amount is calculated based on item.rate*item.qty in Sales Order Item.

but I want to calculate it with item.rate*item.stock_qty.
I really need to override calculate_item_values method in my custom app.

How can I achieve this? Anyone have an idea about it?
Thanks.


#7

Hello All,

Sorry for re-reply.
I really need this. Is there anybody have a solution for it?
Thanks


#8

You can override class methods, check this

We always do simple trick for such customisation.
Change label of Qty - Custom Stock Qty and hide it.
Add new field Qty (Custom Qty)
Write script on selecting item, validate to change Qty to Stock Qty and Make Qty field hidden.


#9

Hello @kolate_sambhaji,
Thanks for the reply, as per your suggested example I tried but still, I am not able to override class method.
my custom app have no any doctype so I override it in Path : my_custom_app=>my_custom_app=>controllers=>taxes_and_totals.py
Thanks.


#10

Its not actual overriding, both method will be called, so you can use alternative way of changing field label for your customisation.


#11

Hi @yogendrasinh,

    Did this work for you? I'm also trying to do the same.