phamos-eu / Swiss-Accounting-Integration

Extending ERPNexts functionality with Swiss QR Integration and Abacus Export
GNU General Public License v3.0
6 stars 14 forks source link

Abacus export with item based tax not successfull #19

Open cdiethelm opened 2 years ago

cdiethelm commented 2 years ago

Hello,

Here is our situation: There are completely deductable positions on invoices which have a separate tax code. The taxrate for these items is 100% included in the item price.

Example: Item 1 - 14.90 CHF Total invoice cost - 14.90 CHF

This is an example file from our old ERP System:

A S Normal D 2418 0 CHF 2021-12-03 2021-12-03 CHF 1904.50 1904.50 470000 470000 0 9999 0 0 (Supplier) (Invoice No) 26253 0 E Normal D 2021-12-03 2021-12-03 CHF 1904.50 1904.50 200000 0 0 0 0 0 (Supplier) (Invoice No) 26253 I 1 0 CHF 0 -1904.50 100.00 100 CH 115 0 (Transaction Number)

This is an example from ERPNext with the Swiss Accounting integration:

<?xml version="1.0" encoding="UTF-8"?>
<!-- This export has data from 2022-02-01 to 2022-03-31 and has 6 Sales Invoices, 1 Purchase Invoices and 0 Payment Entry -->
<AbaConnectContainer>
    <TaskCount>0</TaskCount>
    <Task>
        <Parameter>
            <Application>FIBU</Application>
            <Id>XML Buchungen</Id>
            <MapId>AbaDefault</MapId>
            <Version>2015.00</Version>
        </Parameter>
        <Transaction id="1">
            <Entry mode="SAVE">
                <CollectiveInformation mode="SAVE">
                    <EntryLevel>A</EntryLevel>
                    <EntryType>S</EntryType>
                    <Type>Normal</Type>
                    <DebitCredit>C</DebitCredit>
                    <Client></Client>
                    <Division>0</Division>
                    <KeyCurrency>CHF</KeyCurrency>
                    <EntryDate>2022-03-21</EntryDate>ö
                    <ValueDate>2022-03-21</ValueDate>
                    <AmountData mode="SAVE">
                        <Currency>CHF</Currency>
                        <Amount>14.40</Amount>
                    </AmountData>
                    <KeyAmount>14.40</KeyAmount>
                    <Account></Account>
                    <IntercompanyId>0</IntercompanyId>
                    <IntercompanyCode></IntercompanyCode>
                    <Text1>ACC-PINV-2022-00002-5</Text1>
                    <DocumentNumber>2022000025</DocumentNumber>
                    <SingleCount>1</SingleCount>
                </CollectiveInformation>
                <SingleInformation mode="SAVE">
                    <Type>Normal</Type>
                    <DebitCredit>C</DebitCredit>
                    <EntryDate>2022-03-21</EntryDate>
                    <ValueDate></ValueDate>
                    <AmountData mode="SAVE">
                        <Currency>CHF</Currency>
                        <Amount>14.40</Amount>
                    </AmountData>
                    <KeyAmount>14.4</KeyAmount>
                    <Account></Account>
                    <TaxCode>115</TaxCode>
            <IntercompanyId>0</IntercompanyId>
                    <IntercompanyCode></IntercompanyCode>
                    <Text1>ACC-PINV-2022-00002-5</Text1>
                    <DocumentNumber>2022000025</DocumentNumber>
                    <SelectionCode></SelectionCode>
                </SingleInformation>
            </Entry>
        </Transaction>
    </Task>
</AbaConnectContainer>

Notice that the tax information is not stored in TaxData. This returns the following error in Abacus:

<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type="text/xsl" href="Response.xsl"?>
<AbaResponse>
  <ResponseStateSetting>Warning</ResponseStateSetting>
  <ResponseState>Error</ResponseState>
  <Information>
    <ActionType>IMPORT</ActionType>
    <TimeStamp>21.03.2022 11:56:53.614</TimeStamp>
    <FileName>path</FileName>
  </Information>
  <Statistic mode='Task'>
    <Information>0</Information>
    <Warning>0</Warning>
    <Error>1</Error>
  </Statistic>
  <Messages>
    <Message state='Error' code='3028'>Element TaxCode in SingleInformation ist von unbekanntem Typ.</Message>
  </Messages>
  <Task name='XML Buchungen (1)'>
    <ResponseState>Error</ResponseState>
    <Information>
      <Definition>XML Buchungen</Definition>
      <Mapping>AbaDefault</Mapping>
      <Application>fibu</Application>
      <Version>2015.0</Version>
      <Mandant>2418</Mandant>
    </Information>
    <Statistic mode='Transaction'>
      <TransactionCount>1</TransactionCount>
      <Information>0</Information>
      <Warning>0</Warning>
      <Error>1</Error>
    </Statistic>
    <Transaction name='0' id='1'>
      <ResponseState>Error</ResponseState>
      <Statistic mode='Element'>
        <Information>0</Information>
        <Warning>0</Warning>
        <Error>1</Error>
      </Statistic>
      <Element name='Entry'>
        <ResponseState>Error</ResponseState>
        <Element name='SingleInformation'>
          <ResponseState>Error</ResponseState>
          <Messages>
            <Message state='Error' code='3028'>Element TaxCode in SingleInformation ist von unbekanntem Typ.</Message>
          </Messages>
          <Data name='Type'>
            <ResponseState>Information</ResponseState>
            <Value>Normal</Value>
          </Data>
          <Data name='DebitCredit'>
            <ResponseState>Information</ResponseState>
            <Value>C</Value>
          </Data>
          <Data name='EntryDate'>
            <ResponseState>Information</ResponseState>
            <Value>2022-03-21</Value>
          </Data>
          <Data name='ValueDate'>
            <ResponseState>Information</ResponseState>
            <Value/>
          </Data>
          <Data name='KeyAmount'>
            <ResponseState>Information</ResponseState>
            <Value>14.4</Value>
          </Data>
          <Data name='Account'>
            <ResponseState>Information</ResponseState>
            <Value>0</Value>
          </Data>
          <Data name='IntercompanyId'>
            <ResponseState>Information</ResponseState>
            <Value>0</Value>
          </Data>
          <Data name='IntercompanyCode'>
            <ResponseState>Information</ResponseState>
            <Value/>
          </Data>
          <Data name='Text1'>
            <ResponseState>Information</ResponseState>
            <Value>ACC-PINV-2022-00002-5</Value>
          </Data>
          <Data name='DocumentNumber'>
            <ResponseState>Information</ResponseState>
            <Value>2022000025</Value>
          </Data>
          <Data name='SelectionCode'>
            <ResponseState>Information</ResponseState>
            <Value/>
          </Data>
          <Data name='TaxCode'>
            <ResponseState>Information</ResponseState>
            <Value>115</Value>
          </Data>
        </Element>
      </Element>
    </Transaction>
  </Task>
</AbaResponse>
wojosc commented 2 years ago

@estackhub please assess this issue.

lajidey-foss commented 2 years ago

@wojosc invoices.against_singles always returns empty [ ]. Looking into the return structure and length of "invoices.against_singles"

wojosc commented 2 years ago

Thank you @estackhub . There is something else we need to look at here first I think.

@cdiethelm you would like to reflect "EUSt" right? ERPNext is set to cover this in the Taxes and Charges Table rather than doing this via an item. Is this known to you?

cdiethelm commented 2 years ago

@wojosc Yes, that is known to me. Our issue is that we cannot have different tax codes in the invoice. Example: For the "EUSt", we need tax code 115, for regular taxes 140. There should be a field in the table "purchase taxes and charges" to set an individual account. Right now, this is handled via "Purchase taxes and charges template". We cannot choose multiple templates.

wojosc commented 2 years ago

Hi @cdiethelm from a user persepective...would it be sufficient to have a field "Tax Code" inside the Taxes and Charges Table? grafik

cdiethelm commented 2 years ago

Hello @wojosc, Yes, that would fit our use case. Since the user already has to put in the tax value, he could also put in the tax code.

wojosc commented 2 years ago

@cdiethelm I have added the field on the staging platform. Please have a look.

It won't be available in the Abacus Export yet but you'll be able to check if you can pull all the information over a custom report I have created: grafik

The amounts in the columns between 4 and 5 are the amount of the items and the amount of the tax.

cdiethelm commented 2 years ago

Hello @wojosc , account 115 is present in the view, so that is correct.

image

The other content would have tax code 131 from the template.

cdiethelm commented 2 years ago

@wojosc Please note, that we need that for Purchase Invoice, not Sales invoice.

cdiethelm commented 2 years ago

@wojosc Are there any news on this subject? Anything I could help?

wojosc commented 2 years ago

@cdiethelm as just discussed:

The field for the Swiss Tax Code on the UI will be called "Steuerziffer CH" and carry the technical fieldname steuerziffer_ch to avoid conflict with other tax related fields coming from frappe or third party apps.

We have quickly discussed and tested the use of Accounting Dimensions to quickly employ the field on all accounting relevant transactions documents which are, but not limit to

With implementing the field via the UI the requirement to be able to input and document the "Steuerziffer (Tax Code)" is fulfilled.

Further we will need to map (and remap due to the field name change) the field "steuerziffer_ch" to the Abacus Field as seen in the XML export.

The mapping needs to be done on

Item Level and Sales Taxes and Charges Level. Both on Sales Invoice and Purchase Invoice. Although the Purchase Invoice has the higher priority

Tasks

@cdiethelm please quickly let me know if there are further steps to take befor we start with this. Thank you.

wojosc commented 2 years ago

@estackhub fyi

cdiethelm commented 2 years ago

@wojosc I think its all clear now. Looks good to me. 👍

cdiethelm commented 2 years ago

@wojosc We have an error with the export. Should that be an optional value?

App Versions

{
    "erpnext": "14.0.0-dev",
    "frappe": "14.0.0-dev",
    "swiss_accounting_integration": "0.0.6",
    "wiki": "0.0.1"
}

Route

Form/Abacus Export/jan

Trackeback

Traceback (most recent call last):
  File "apps/frappe/frappe/desk/form/save.py", line 21, in savedocs
    doc.submit()
  File "apps/frappe/frappe/model/document.py", line 997, in submit
    return self._submit()
  File "apps/frappe/frappe/model/document.py", line 986, in _submit
    return self.save()
  File "apps/frappe/frappe/model/document.py", line 295, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 346, in _save
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1065, in run_post_save_methods
    self.run_method("on_submit")
  File "apps/frappe/frappe/model/document.py", line 920, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1242, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1226, in runner
    add_to_return_value(self, f(self, method, *args, **kwargs))
  File "apps/swiss_accounting_integration/swiss_accounting_integration/__init__.py", line 167, in attach_xml
    attach(doc.company, doc.start_date, doc.end_date, doc.doctype, doc.name)
  File "apps/swiss_accounting_integration/swiss_accounting_integration/__init__.py", line 159, in attach
    gl_xml = gl(company, start_date, end_date)
  File "apps/swiss_accounting_integration/swiss_accounting_integration/__init__.py", line 92, in gl
    inv_amt(item, item.expense_account, inv.currency,
  File "apps/swiss_accounting_integration/swiss_accounting_integration/utils.py", line 174, in amount
    'tax_code': item.tax_code or "312",
AttributeError: 'PurchaseInvoiceItem' object has no attribute 'tax_code'

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 67, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 38, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 76, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1493, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/desk/form/save.py", line 21, in savedocs
    doc.submit()
  File "apps/frappe/frappe/model/document.py", line 997, in submit
    return self._submit()
  File "apps/frappe/frappe/model/document.py", line 986, in _submit
    return self.save()
  File "apps/frappe/frappe/model/document.py", line 295, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 346, in _save
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1065, in run_post_save_methods
    self.run_method("on_submit")
  File "apps/frappe/frappe/model/document.py", line 920, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1242, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1226, in runner
    add_to_return_value(self, f(self, method, *args, **kwargs))
  File "apps/swiss_accounting_integration/swiss_accounting_integration/__init__.py", line 167, in attach_xml
    attach(doc.company, doc.start_date, doc.end_date, doc.doctype, doc.name)
  File "apps/swiss_accounting_integration/swiss_accounting_integration/__init__.py", line 159, in attach
    gl_xml = gl(company, start_date, end_date)
  File "apps/swiss_accounting_integration/swiss_accounting_integration/__init__.py", line 92, in gl
    inv_amt(item, item.expense_account, inv.currency,
  File "apps/swiss_accounting_integration/swiss_accounting_integration/utils.py", line 174, in amount
    'tax_code': item.tax_code or "312",
AttributeError: 'PurchaseInvoiceItem' object has no attribute 'tax_code'

Request Data

{
    "type": "POST",
    "args": {
        "doc": "{,\"doctype\":\"Abacus Export\"}",
        "action": "Submit"
    },
    "btn": {
        "jQuery3600018627082573897671": {
            "events": {
                "click": [
                    {
                        "type": "click",
                        "origType": "click",
                        "guid": 884,
                        "namespace": ""
                    }
                ]
            }
        }
    },
    "freeze": true,
    "headers": {},
    "error_handlers": {},
    "url": "/api/method/frappe.desk.form.save.savedocs"
}

Response Data

{
    "exception": "AttributeError: 'PurchaseInvoiceItem' object has no attribute 'tax_code'"
}
wojosc commented 2 years ago

@cdiethelm the change was only implemented for the Sales Invoice for the moment. We should test that first.

For now, try adding a field tax_code to your Purchase Invoice Item to solve your error. If you need help, please call. Thank you.