frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
20.85k stars 7.15k forks source link

Powerfull taxation system #3536

Closed MaxMorais closed 9 years ago

MaxMorais commented 9 years ago

New Taxation system

@rmehta edit: Moved original description to first comment

MaxMorais commented 9 years ago

Hi, guys!

I have a big scenario there in Brazil that implies in the fact of ERPNext is not able to calculate the Brazilian taxes, because our taxes aren't simple taxes, we have a lot of variables in the taxation system.

Only for you understand a bit our scenario: Brazilian Eletronical Invoice Form

TAX Basis for Each Item

The caculation of the group of taxes that will be applied in a Item according our rules, can be distilled in 40 fields.

With in mind, the difficulties that I have found to calculate my local taxes in the ERPNext

A domain is like a "Tax Group" but when I mean about a Tax domain, I understood the group of properties that will be used in tax calculation.

I have others things related to the tax system that I dont remember and I know that it is a very specific solution, but the most important thing that I want is, how I can provide a way for override the tax calculation method.

Currently the hooks works like a decorator, so the result of a function is passed to another, but I want redefine the tax calculation method, without do big changes in the core, I'm trying to manage my core synced with your core without headaches, and for now it is fine.


Another detail, strange rules rule the BR taxation system, 25% can be 25% or 33%, let me explain

Supose that Webnotes is a brazilian company and is a product reseller. So, Webnotes puchase a product for sell and the purchase value of the Purchase Invoice is BRL 1.000,00 and the TAX in the Invoice is 18%.

The Journal Entry will be

Entry Credit Debit
Supplier 1.000,00
Stock 820,00
Taxes 180,00
Total 1000,00 1000,00

Now the Webnotes will sell the product with a profit of 100%

So, the sell calculation is BRL 820,00 + 100,00% = 1640,00 But the correspondent value represent only 82% of the sell value because it dont have the amount of tax incrementing in the amount So 82% = 100% - 18% => Sell value is equal to 1640,00 / 82% = 2000,00

The sell value is BRL 2.000,00

In the Sales Invoice the tax will be defined as 18% but:

The Tax total is 360,00 The Invoice total is 2000,00

The real tax is 1640,00 / 360 x 100 = 21,951%

rmehta commented 9 years ago

@MaxMorais we are working on default taxes for various countries too. I think we can build in a default taxes in the product itself based on the country.

@anandpdoshi is working on including default taxes for US

Do you have a design proposal?

MaxMorais commented 9 years ago

The model that I have to propose is the same of Odoo, the fiscal rule https://github.com/OCA/account-fiscal-rule to help in tax decision rules.

Another thing to discuss is: Today the taxes are Accounts When I Add a custom-field to the tax, it will be disponible in all accounts.

What is the best way to manage the customization over the accounts ? Dinamic Links are the solution?

rmehta commented 9 years ago

account-fiscal-rule Looks interesting. Can you mock it up? @anandpdoshi do check this.

MaxMorais commented 9 years ago

fiscal rule

This is the actual scheme in Odoo is in above Image, the mapper, compare these options to define the validity of the rule and apply the tax

I believe that we can simplify somethings, like the From Section, only looking for the company, but it the Odoo scheme make sense when the company have a external Wharehouse, but actually this fact is not completely considered by ERPNext, we have warehousing management, but we dont consider it as a Geo Location.

The Doctype can be:

When we talk about outgoing documents (Sales, Delivery) this scheme make sense, but when we talk about incoming documents (Purchase, Receipt), it only make sense to audity the received document, to ensure that the taxe is the same as expected.

The VAT Rule is a rule to determine the tax based in the Person Type, Company or Individual.

The mapper have a mechanism very close with the validate_with_previous_doc in the Transaction Base controller.

I believe that we can create a doctype named fiscal rule, but we will need manage a way of control the way of the mapper works based or on config or on hooks.

I believe thar in this case, if we provide a too a Fiscal Rule Template and in the Template we can manage the options that will be passed to the mapper method, can be very powerfull.

I'm thinking in configurable things like the DocType mapper was in the past.

MaxMorais commented 9 years ago

related with #3255

rmehta commented 9 years ago

@MaxMorais All great points. We should also explore adding this in the Tax Template itself, but it may not work if there are additional "Charges" to be applied.

Maybe we should call it "Taxes and Charges Rule" to make consistent naming with ERPNext. "Fiscal Rule" is very vague IMO

These can be applied here:

https://github.com/frappe/erpnext/blob/develop/erpnext/controllers/taxes_and_totals.py#L75

Do you want to start this project? We will be happy to join in.

MaxMorais commented 9 years ago

@rmehta I agree with your points! I'll start it, the unique point is a doubt about how we can turn the calculations extensible ? The unique part of coreflow that is working is the formula solver, we can define a formula used to calculate the tax?

rmehta commented 9 years ago

Lets hard-code the calculations for each country in a separate file as a part of the repo. In my view, it will be much easier to maintain in the long run. We could do core flow at a later point as a separate project.

MaxMorais commented 9 years ago

Nice @rmehta, only a final question, any idea about how you manage the custom fields in a Tax? In my case I have differents fields, for different taxes

rmehta commented 9 years ago

There are a lot of fields. How about a separate DocType with the statutory fields that can be linked to invoice. Sales / Purchase transactions already have many fields.

rmehta commented 9 years ago

@MaxMorais hey, any update? We can start working on this.

robertbecht commented 9 years ago

Hi @MaxMorais & @rmehta,

Believe a overhaul of the current rather simplistic charges and taxes would really be a major improvement of Erpnext.

One element could be considered and that is reporting. So not only the rules, but also a definition of what the Tax/revenue agency wants to receive on a regular basis.

Second: would separate taxes and other charges

Plse note that the European Union has some 28 member states with i believe relative uniform VAT rules. I have implemented these ( part of) long ago in Erpnext. Major elements: National VAT, Intercommunity transactions between tax registered companies with "transferred VAT". ( if I buy goods in the EU outside NL, i do not pay VAT, but have to declare amounts to NL Tax authorities. I do this by imposing the same tax positive and negative ( eg 6% and minus 6%). So i do not actually pay, but can calculate total for reporting to tax office

Good luck with this important exercise/improvement

MaxMorais commented 9 years ago

@rmehta Sorry for the time, I'm busy these days!

So, I need work on this feature, this is most important to me! But, starting the Tax and Changes Rules, I fell that the above sketch are not good! I have small doubts but they have a big impact for me and for this module.

My big difficulty is separating what is just part of my reality and which can be useful for everyone.

I was looking for this sketch and looking for "Price Rule", your layout is very clean, but my proposed layout work to me, missing small constraints.

For example, in my reality if I have 2 warehouses, one on the São Paulo State, and other in the Rio de Janeiro State, and I made a sell, that will be delivered for the Customer, that are in Minas Gerais State, if I'll do a transfer from Rio to São Paulo to do the delivery in Minas Gerais, I'll pay 21% of ICMS (Tax for Item Movement) between warehouses, and 17% of ICMS for do the Delivery, If I'll do 2 deliveries, one from São Paulo, another from Rio, to Minas, I'll pay 17% of ICMS from São Paulo to Minas and 18.5% ICMS from Rio to Minas. So, for me Wharehouses are phisical places that have a address, and can be in my location or not.

You must be thinking that this is not very common, but is far more common than you might think, small businesses do not maintain warehouses, they do is maintain a warehouse on suppliers where they can choose to transfer the goods direct to the customer, or send to another warehouse for this warehouse carry out the delivery to the customer.

Because this, I'm with a difficulty to be clear about what ERPNext need for all, can you guide-me with the enumeration of the requirements, based on your experience with your customers?

rmehta commented 9 years ago

@MaxMorais There is already an option for From Country, From State in your design. We will have to wire this while processing the rules. It should not be too hard.

You can might have to make 2 invoices for the case when you ship from different locations. Do you know at the time of booking where you will ship from?

Do you have an ETA on this?

robertbecht commented 9 years ago

Hi there,

Wrote some comments but yesterday but never mailed them. I believe, not sure, have to check.

Working for a faculty where spatial information, GIS, satellite remote sensing is the cream and butter, I am always interested in "spatial things". (www.itc.nl)

Spatial and ERP have been discussed before related to agriculture ( a farmer in Africa wanted to link a field with a crop to ERP). This discussion also relates to location. Taxes are levied if an Item moves from location A to B.

I have been discussing informally here at ITC that the integration of ERP, Spatially explicit, and location based services is still a field in its infancy. I would like to see may collegues from GeoInformatics to take this up with few MSc or PhD students.

If one Googels spatial ERP there are a few hits only. ESRI (the leading GIS company) has this PP and mainly refers to SAP (the leading ERP) _http://www.redlands.edu/docs/URSB/Transps-Chp4-Enterprise_GIS_-_with_Pidpa-210.ppt http://www.redlands.edu/docs/URSB/Transps-Chp4-Enterprise_GIS_-_with_Pidpa-210.ppt_

Coming Back to taxes: the tax is , i believe , determined by the location history (location as a function of time). A movement of an ITEM between two locations invokes a tax rule , valid at that time, that is applied on the price. So maintaining a table of time and location allows to calculate tax.

Of course, just entering two locations for a transaction will aloow to calculate tax.

However, a more fundamental approach to bring a location into Erpnext may bring long term benefits: location in a ware house, analysis of supply chains, distribution of customers etc.

Postal Address are well developed in the western world. If you mail me a letter at 7522JA,59 i will receive it. Ireland very recent introduced one of the most sophisticated postal ZIP systems.

For large logistic companies (DHL, UPS etc) addressing is key. Howver, The largest part of the world does not have a adress or a very vague one "off Ghandi Road after Barclays Bank" and similar.

An relatively exact system is based on coordinates (lat, long, projected on a geoide, WSG84 emerging as a standard). There are several webservices that translate lat,long in an adress and the opposite.

An very interesting development is "Our goal is for what3words to become a global standard for communicating location." see : http://what3words.com/ http://what3words.com/

I realize this discussion goes way beyond the objectives @MaxMorais https://github.com/MaxMorais to implement taxes, but maybe in the design of a universal tax calculator one should take a more fundamental approach towards location/position, since i believe this may pay-off in other domains

Just to start thinking about a "spatially enabled ERP". From a competive point of few, this would be a quite unique feature I believe.

I copied Javier Morales ( a pure geo-ict collegue) robert

On Thu, Jul 16, 2015 at 7:42 AM, Rushabh Mehta notifications@github.com wrote:

@MaxMorais https://github.com/MaxMorais There is already an option for From Country, From State in your design. We will have to wire this while processing the rules. It should not be too hard.

You can might have to make 2 invoices for the case when you ship from different locations. Do you know at the time of booking where you will ship from?

Do you have an ETA on this?

— Reply to this email directly or view it on GitHub https://github.com/frappe/erpnext/issues/3536#issuecomment-121839949.

MaxMorais commented 9 years ago

Hi, @robertbecht you comments about localization are close with my view about What a is powerfull tax system.

The question, is addresses in ERP are too generical, so It solve the issue of create write a address in a mail, but in a territorial vision it is to vague to me, because my territories are direct connected with a addresses and the addresses needs know too important things, the cities and/or the states, based on the Brazilian ZIP Codes, CEP, I only know the City Name and State Name, but the IBGE (Brazilian Institute of Geography and Statistics), provide a code for each city and state in the country and this codes are a the base of my local rules.

BTW there we have webservices that provide the Address information based on our Zip Codes, including the IBGE codes, for me a just integration with this webservices solve a small part of my requirements.

rmehta commented 9 years ago

@robertbecht moving the spatial issue on a new topic.

@MaxMorais don't connect with territory, work with addresses (territory is only for MIS). Does that solve your problem?

This design is good enough to start, once we start building, we will find better solutions

rmehta commented 9 years ago

@MaxMorais did you get started on this? Or @neilLasrado will start this.

MaxMorais commented 9 years ago

Hi, @rmehta, I dont started it.

2015-07-23 6:36 GMT-03:00 Rushabh Mehta notifications@github.com:

@MaxMorais https://github.com/MaxMorais did you get started on this? Or @neilLasrado https://github.com/neilLasrado will start this.

— Reply to this email directly or view it on GitHub https://github.com/frappe/erpnext/issues/3536#issuecomment-124033986.

Best Regards.

Maxwell Morais Python Developer powered by Webnotes framework <3 +55 11 954329659