Set accounting date based on the effective date of related shipments

Continuing the discussion from Prevent using same sequence on earlier customer invoice: which date to use? @sergyo shared a requirement about the accounting date in Spain.

Currently, tryton does not set any accounting date and the user must set it manually.
But following this requirement we may set the accounting date based on the account_invoice_stock relation. As each invoice is realted to shipments, we can deduce the max effective date (in case of grouping several shipments) and set it on the invoice.

My idea is to set the accounting date when posting invoice if the accouting date is empty, so the user does not need to care about setting the accounting date manually as the system will set from him and in case the date is not valid (the period is already posted) the user can always modify it. Does it make sense? Any better ideas?

I will also like if this is usefull for other countires so we can make it generic feature for tryton.
Also if you think that will cause any issue in some countries, please raise your voice.

Please could you define what is “accounting date of invoice taxes”?

It is the accounting date of the invoice, that is used for the move and for tax reports. This is already implemented in Tryton so we just need to set the accounting date on the invoice and the proper tax report will be produced.

Then this makes no sense for me.

Then we are probably not undestanding each other. What does not make sense for you?

To not book invoice when they are emitted.

This has been already explained in the linked topic:

The fact is that the company delivers some goods at 30/12/2021 but we do not issue the invoice until 15/01/2021. So the user needs to set the accounting date to 30/12/2021 as the Spanish law requires that the taxes should be declared when the goods are set (which is before the invoices is posted), so the move should be booked at this date.

So my proposal is about setting the accounting date automatically as tryton already knows when the goods are sent instead of forcing the user to set them manually.

1 Like

For me the proposal can not work because:

  • invoice may contain different stock move dates
  • the requirement is about tax declaration period and not the accounting date

Indeed the requirements is much more similar to account_tax_cash module but based on the shipping date (which should be converted into accounting period).
Also I suspect that the rule is not symmetric between customer and supplier invoice.

No, rule is only for customer shipments/invoices. I forgot to mention that, sorry.

Yes but I do not see any issue as far as we do not group invoices with diferent accounting periods . We may take that in account by adding the period on the invoice grouping fields.

Maybe but in this case we now at the moment of posting the effective date but in account_tax_cash the period when the invoice should be paid is unknown. Note that this is just applied when invoice is created based on sent shipments.

There is no constraint in the code that a complete invoice will have only stock move from the same period.

No you do not always know because there are no constraint in the code. But also you may have many different dates.

Your proposal design does not work.

Nothing prevents to add some constraint if this is really required :pleading_face:

I’m just discussing ideas to try to find the right design.