Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how too #1

Open
thiva7 opened this issue Jun 24, 2024 · 1 comment
Open

how too #1

thiva7 opened this issue Jun 24, 2024 · 1 comment

Comments

@thiva7
Copy link

thiva7 commented Jun 24, 2024

Καλησπερα ,

Προσπαθησα λιγο κοιτωντας το κωδικα σου να στειλω παραστατικα αλλα δεν δουλεψε. λογικα κατι κανω λαθος

from mydata import models_v1_0_8
from mydata import client


InvoiceProvider = models_v1_0_8
invoice = InvoiceProvider.AadeBookInvoiceType()
invoice_pay = InvoiceProvider.AadeBookInvoiceType.payment_methods
issuer = InvoiceProvider.PartyType()
counterpart = InvoiceProvider.PartyType()
header = InvoiceProvider.InvoiceHeaderType()
paymentDetails = InvoiceProvider.AadeBookInvoiceType.PaymentMethods()
prod1 = InvoiceProvider.InvoiceRowType()

issuer.vat_number = "123456789"
issuer.country = "GR"
issuer.branch = "0"


counterpart.vat_number = "997483917"
counterpart.country = "GR"
counterpart.branch = "0"

counterpart.address = InvoiceProvider.AddressType()
# counterpart.address.street = "ΑΓΙΟΥ ΠΑΥΛΟΥ 3"
# counterpart.address.postal_code = "54645"
# counterpart.address.city = "ΘΕΣΣΑΛΟΝΙΚΗ"

header.series = "ff"
header.aa = "0001"
header.issue_date = "2021-01-01"
header.invoice_type = "1.1"
header.currency = "EUR"

paymentDetails.type_value = "1"
paymentDetails.amount = "100.00"
paymentDetails.payment_method_info = "I paid in cash."


prod1.line_number = "1"
prod1.net_value = "100"
prod1.vat_category = "1"
prod1.vat_amount = "24"

prod1.income_classification = InvoiceProvider.IncomeClassificationType()
prod1.income_classification.classification_type = "E3_106"
prod1.income_classification.classification_category = "1"
prod1.income_classification.amount = "100"

invoice.issuer = issuer
invoice.counterpart = counterpart
invoice.invoice_header = header
invoice.payment_methods = paymentDetails
invoice.invoice_details = prod1


invDoc = InvoiceProvider.InvoicesDoc()
invDoc.invoice = invoice

TryToSend = client.Client(username="user", token="pass" , prod=False)
TryToSend.send_invoices( invoices=invDoc)
@apyrgio
Copy link
Owner

apyrgio commented Jun 26, 2024

Χμ, νομίζω πως το Python αντικείμενο που δημιουργείς δεν αντιστοιχεί σε αυτό που δέχεται το SendInvoices endpoint.

Για παράδειχμα, αν μετατρέψεις σε XML το παραπάνω αντικείμενο, χρησιμοποιώντας την συνάρτηση client.serialize(), καταλήγεις σε αυτό:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:InvoicesDoc xmlns:ns0="http://www.aade.gr/myDATA/invoice/v1.0">
  <ns0:invoice>
    <ns0:issuer>
      <ns0:vatNumber>123456789</ns0:vatNumber>
      <ns0:country>GR</ns0:country>
      <ns0:branch>0</ns0:branch>
    </ns0:issuer>
    <ns0:counterpart>
      <ns0:vatNumber>997483917</ns0:vatNumber>
      <ns0:country>GR</ns0:country>
      <ns0:branch>0</ns0:branch>
      <ns0:address/>
    </ns0:counterpart>
    <ns0:invoiceHeader>
      <ns0:series>ff</ns0:series>
      <ns0:aa>0001</ns0:aa>
      <ns0:issueDate>2021-01-01</ns0:issueDate>
      <ns0:invoiceType>1.1</ns0:invoiceType>
      <ns0:currency>EUR</ns0:currency>
    </ns0:invoiceHeader>
    <ns0:paymentMethods/>
    <ns0:invoiceDetails>
      <ns0:lineNumber>1</ns0:lineNumber>
      <ns0:netValue>100</ns0:netValue>
      <ns0:vatCategory>1</ns0:vatCategory>
      <ns0:vatAmount>24</ns0:vatAmount>
      <ns0:incomeClassification>
        <ns1:classificationType xmlns:ns1="https://www.aade.gr/myDATA/incomeClassificaton/v1.0">E3_106</ns1:classificationType>
        <ns1:classificationCategory xmlns:ns1="https://www.aade.gr/myDATA/incomeClassificaton/v1.0">1</ns1:classificationCategory>
        <ns1:amount xmlns:ns1="https://www.aade.gr/myDATA/incomeClassificaton/v1.0">100</ns1:amount>
      </ns0:incomeClassification>
    </ns0:invoiceDetails>
  </ns0:invoice>
</ns0:InvoicesDoc>

Όμως, το xml που πρέπει να στείλεις έχει αυτή την μορφή:

<?xml version="1.0" encoding="UTF-8"?>
<AadeBookInvoiceType>
 <ns0:issuer xmlns:ns0="http://www.aade.gr/myDATA/invoice/v1.0">
   <ns0:vatNumber>123456789</ns0:vatNumber>
   <ns0:country>GR</ns0:country>
   <ns0:branch>0</ns0:branch>
 </ns0:issuer>
 <ns0:counterpart xmlns:ns0="http://www.aade.gr/myDATA/invoice/v1.0">
   <ns0:vatNumber>123456789</ns0:vatNumber>
   <ns0:country>GR</ns0:country>
   <ns0:branch>0</ns0:branch>
 </ns0:counterpart>
 ...
</AadeBookInvoiceType>

Για να φτάσεις σε ένα τέτοιο XML, πρέπει η τελική κλάση να είναι το AadeBookInvoiceType, όχι η InvoicesDoc. Π.χ., δοκίμασε κάτι τέτοιο ( ⚠️ untested ⚠️ ):

- invoice.issuer = issuer
- invoice.counterpart = counterpart
- invoice.invoice_header = header
- invoice.payment_methods = paymentDetails
- invoice.invoice_details = prod1
- invDoc = InvoiceProvider.InvoicesDoc()
- invDoc.invoice = invoice
+ invDoc = InvoiceProvider.AadeBookInvoiceType(issuer=issuer,
+                                              counterpart=counterpart,
+                                              invoice_header=header,
+                                              payment_methods=paymentDetails,
+                                              invoice_details=prod1)

Τέλος, για να σιγουρευτείς ότι το Python class σου περνάει validation πριν το στείλεις στην ΑΑΔΕ, μπορείς να το κάνεις XML με την client.serialize(), και μετά να το parseάρεις με το CLI command

mydata [options] invoices validate /path/to/invoice.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants