Calculating a Hash value for each posted invoice

Hello guys, I hope everybody is doing all right.

Let me tell you that I’m almost finish with Tryton module to get a certification according to the Angolan authorities. It’s been a really good journey, lot’s to learn about Trytond infrastrutute as well as python as a programming language. Both are really good and solid.

After finishing the process of database data collection and exporting to an xml file, I need to add a Hash value. The purpose of this hash value is to digitally sign a document created. For example, every time an invoice is posted, a hash value must be created and saved so it can be included in the SAFT reporting file.

So, I suppose it will be a function field, so I can call a method and calculate the hash value from the invoice data. Until here it’s all right :slight_smile:. However, I’m struggling to create the column in the database and then create a new hash value when an invoice is posted.

Can you guys help me with this?

Thanks

I think the best is to generate the hash of the exported xml file. This will ensure an unique hash for each generated file. You can generate a md5 hash of the file by using a python method.

Yes. It looks interesting and more efficient, because it will be just one digital signature for all file. However, certain documents reported in the SAFT file need a hash value with a digital signature. One of the examples is the invoices, which requires that each invoice reported must be signed through SHA1 with an RSA asymmetric algorithm. The hash value will be calculated from a string with values taken from the invoice to be signed, such as invoice number, invoice date, gross total.

I’m using something similar to this to sign each invoice with state equal to posted.

You have to extend the post process of the invoice. Look in invoice.py from the account_invoice module. There you will find a workflow transition that is posting invoices. At that moment also an invoice number is added. You have to extend that functionality with your hashing.

Why not just creating a readonly Char field and store the hash into it? I assume the hash is created once.

We once discussed using horodating in the French mailing list (sorry, it is in French).
The subject was ‘Loi de finance 2016 (suite)’ in the late 2017 timeframe.
This is separate but potentially simultaneous with digital signing of the invoice itself.

Hey @edbo,

Thank you so much for your reply. It helped me figuring out the process of extending a Tryton module work.

As you recommended, I extend the post process of the invoice to include a hash value in every posted client invoices.

Yes indeed, the hash value is created only once, so I create a Text field for it so it can accommodate all 172 bytes of characters.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.