# Invoice delegation

**URL:** https://discuss.tryton.org/t/invoice-delegation/1496
**Category:** Ideas
**Tags:** accounting
**Created:** [June 21, 2019, 12:01pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496 "2019-06-21T12:01:22Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![wifasoi](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wifasoi](https://discuss.tryton.org/u/wifasoi)
#### Post date: [June 21, 2019, 12:01pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/1 "2019-06-21T12:01:22Z")

</div>

From [Expense reimbursement](https://discuss.tryton.org/t/expense-reimbursement/1480) discussion:

## Rational

Sometimes you need to delegate the purchase of goods, but the invoice need to be in the company name.  
It can also be useful if the customer delegate someone (the customer accountant for example), to keep track who need to pay the invoice on behalf of the customer.  
For this reason it wold be useful to have a “delegated to party” field in the invoice.

## Theory of operation

### supplier invoice

When you post the invoice it will also create a payable move on behalf of the delegated party (if the field is not empty), and it will considered the invoice paid.

### customer invoice

When you post the invoice it will generate also a receivable move for the delegated party.  
In this case the invoice will not be automatically paid until the receivable move is not reconciled

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [June 21, 2019, 1:08pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/2 "2019-06-21T13:08:46Z")

</div>

> [@wifasoi](#):
>
> ### customer invoice
> 
> When you post the invoice it will generate also a receivable move for the delegated party.  
> In this case the invoice will not be automatically paid until the receivable move is not reconciled

Do we really have to take care about the customer invoices?

For me it is not rellevant that the customer invoice is paid by a third party as you will have the invoice paid and you do not have to do anything else.

In the supplier case it’s important to know that the invoice is paid (so you will not pay it twice) and also know that the amount is owed to another party.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [June 21, 2019, 1:25pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/3 "2019-06-21T13:25:30Z")

</div>

> [@pokoli](#):
>
> Do we really have to take care about the customer invoices?
> 
> For me it is not rellevant that the customer invoice is paid by a third party as you will have the invoice paid and you do not have to do anything else.

Yes, if your are doing direct debit you must take from the right party.

> [@pokoli](#):
>
> In the supplier case it’s important to know that the invoice is paid (so you will not pay it twice)

I do not think it should be considered as paid until the delegate is paid.

---

<div class="post-metadata">

### Author: ![wifasoi](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wifasoi](https://discuss.tryton.org/u/wifasoi)
#### Post date: [July 1, 2019, 10:14am UTC](https://discuss.tryton.org/t/invoice-delegation/1496/4 "2019-07-01T10:14:53Z")

</div>

Ok, I need this feature, so I’ll try to implement it.  
One technical question:  
Should I create a payable move based on the “delegated party” payable/receivable (instead of the party in the invoice)or should i create another move “linked”? (reconciled with the one generated from the invoice and the reconcile status delegate\_to this new move)(In this case this should be an action/wizard IMHO)

The first case is the simplest to implement, but after you post the invoice, this should/cannot be changed easily, the user need to create a move manually if the delegate changes.  
The second case is more flexible (sometimes you send group of people and don’t know who will pay for the invoice), and the delegation can be changed via the wizard.

I’m more in favor of the first case, but I want your opinion on this.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [July 1, 2019, 10:35am UTC](https://discuss.tryton.org/t/invoice-delegation/1496/5 "2019-07-01T10:35:24Z")

</div>

I think it should be done on two steps for reporting purpose. The original party is the one who is buying/selling. So if we do report based on cash flow, it is important to have a trace on the original party accounts.  
Also I think this operation should be manageable on the invoice with a field to fill but also directly on a payable or receivable line. It should be quite similar to the [grouping method](https://bugs.tryton.org/issue8213).

---

<div class="post-metadata">

### Author: ![wifasoi](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wifasoi](https://discuss.tryton.org/u/wifasoi)
#### Post date: [July 1, 2019, 11:39am UTC](https://discuss.tryton.org/t/invoice-delegation/1496/6 "2019-07-01T11:39:06Z")

</div>

so it’s more or less second option(but not in a wizard form)?  
Let the invoice module create the receivable/payable move(in favor of the “invoice party”,  
but if the “delegate party” field is populated, create another linked payable/receivable move(reconciled, and the reconcile status delegated to this new move) in favor of the “delegated party”.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [July 1, 2019, 12:35pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/7 "2019-07-01T12:35:40Z")

</div>

> [@wifasoi](#):
>
> so it’s more or less second option(but not in a wizard form)?

Yes but I think a wizard is also needed. Indeed the wizard and the invoice should call the same method.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [August 3, 2019, 9:08am UTC](https://discuss.tryton.org/t/invoice-delegation/1496/8 "2019-08-03T09:08:19Z")

</div>

I have an use case which seems suitable for this feature but I’m not sure if will be completly supported:

When working with as an accoutant sometimes you pay in advance some amouts for your customers and include this amount on the services invoice. But the invoice of the advanced amount is always in the name of your customers (as the customer is responsible of paying it). This is called [suplido](https://debitoor.es/glosario/suplido) in Spanish, don’t know how they name on other languages.

So from the accountant point of view they will create one invoice with two lines:

- One for the service (with VAT)
- Other with the advanced amount (without VAT)

And then from the customer point of view it will receive two invoices:

- One from the accountant including both lines and which will be the one that will be paid
- Another from the real supplier which the total amount is inclued on the accountant invoice (which is delegated to the accountant)

The issue here is with the first invoice of the customer, which includes a line which is not a expense and as we only allow expenses on supplier invoices it’s not possible to add use the correct account for this invoice.

[Here are some examples of the required moves](https://www.contabilidae.com/suplidos-iva-contabilizacion-ejemplos/) for this specific case.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 4, 2019, 7:11am UTC](https://discuss.tryton.org/t/invoice-delegation/1496/9 "2019-08-04T07:11:45Z")

</div>

I do not understand how can there be two invoices for the same service managed by two different entities. Only one entity must have received the invoice and I guess it is the accountant otherwise it would not know the amount to advance.

I do not think it is very wise from the accountant to mix its own services and the advance payments he does in the same invoice because it is confusing for his customers.

Indeed I think this looks more like a “employee”'s expense than a supplier/customer flow. So for me, the accountant must create a document/letter to request reimbursement to attach with the original invoice.

---

<div class="post-metadata">

### Author: ![wifasoi](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wifasoi](https://discuss.tryton.org/u/wifasoi)
#### Post date: [August 5, 2019, 3:06pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/10 "2019-08-05T15:06:41Z")

</div>

Ok,  
For now i implemented the “naive solution” (more as a proof of concept):

- create a move based on to `lines_to_pay`
- create an “opposite line” and reconcile it to the old payable/receivable line
- delegate the reconciliation to the new payable/receivable line with another party
- write the party to the “delegated\_party” field

seams to work nice for my user case, but there are some side effect i want to discuss first:

- Should the “opposite line” be more like a cancel move (credit/debit negative), or just a move with the credit/debit swapped.
- the pay wizard will try to create a move for the original party, should the wizard take into account the delegated party?
- the amount to pay will show zero, should be display the amount the delegated party should pay?(as a separated field perhaps)
- payment line (i didn’t check it) will probably be affected as well, should i fix it, or just list the payment line the original party has payed?
- for now the “original party” can pay some line of the invoice, and then delegate the rest (this is because I use the `lines_to_pay` field), is this behavior a feature or a bug?
- How should i deal with partially payed line (if this is possible, didn’t check it)?
- you can chain delegate in theory (you can change the delegated party and create a chain of moves, the one that will need to pay the invoice is the last person on the chain), should i leave it as a feature?
- should i create a `cancel delegation` option? or this will be something the feature above can provide? (going full circle by delegating to the “original party”)

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 5, 2019, 3:32pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/11 "2019-08-05T15:32:47Z")

</div>

> [@wifasoi](#):
>
> write the party to the “delegated\_party” field

What is the purpose of this field?

> [@wifasoi](#):
>
> Should the “opposite line” be more like a cancel move (credit/debit negative), or just a move with the credit/debit swapped.

I think negative value will be better because it will not increase artificially the total of debit and credit.

Other questions can not be answered without viewing the code.

---

<div class="post-metadata">

### Author: ![wifasoi](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wifasoi](https://discuss.tryton.org/u/wifasoi)
#### Post date: [August 5, 2019, 3:50pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/12 "2019-08-05T15:50:32Z")

</div>

the code is not complete, this is some side effect i witnessed/think could append and what should the module/path should do.  
the first “functional” code is here: [invoice delegation ($27) · Snippets · GitLab](https://git.mittelab.org/snippets/27)  
it’s dirty.. it not complete… just an experiment.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 5, 2019, 4:04pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/13 "2019-08-05T16:04:34Z")

</div>

> [@wifasoi](#):
>
> the amount to pay will show zero, should be display the amount the delegated party should pay?(as a separated field perhaps)

So you are talking about the amount to pay on the **invoice**.  
I think the `lines_to_pay` should provide the delegated lines instead of the original.

> [@wifasoi](#):
>
> payment line (i didn’t check it) will probably be affected as well, should i fix it, or just list the payment line the original party has payed?

The party constraint on payment lines should be updated to use the delegate party.

> [@wifasoi](#):
>
> for now the “original party” can pay some line of the invoice, and then delegate the rest (this is because I use the `lines_to_pay` field), is this behavior a feature or a bug?

For me, this can not happen because:

- delegation should be done on the invoice before posting
- or if done manually it is at the move line level which will remove the possibility to add payment lines on the invoice.

> [@wifasoi](#):
>
> How should i deal with partially payed line (if this is possible, didn’t check it)?

Delegation on the invoice should be done prior to posting. So there is no partial case.

> [@wifasoi](#):
>
> you can chain delegate in theory (you can change the delegated party and create a chain of moves, the one that will need to pay the invoice is the last person on the chain), should i leave it as a feature?

Yes.

> [@wifasoi](#):
>
> should i create a `cancel delegation` option?

I do not think. The accountant will cancel/delete the move or make a new delegation.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [August 5, 2019, 6:20pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/14 "2019-08-05T18:20:24Z")

</div>

> [@ced](#):
>
> I do not understand how can there be two invoices for the same service managed by two different entities. Only one entity must have received the invoice and I guess it is the accountant otherwise it would not know the amount to advance.

It’s only one invoice, but the accountant uses the invoice line to request the amount paid in your name. After request the payment he sends you the final invoice which which it paid in advance. Normally you receive first the accountant invoice (with the full amount) and then the invoice of the other supplier which has been already been paid by the accountant.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 5, 2019, 7:53pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/15 "2019-08-05T19:53:43Z")

</div>

> [@pokoli](#):
>
> the accountant uses the invoice line to request the amount paid in your name

For me, it is wrong because he did not sale any services with this line. It is an abuse of the invoice. It must send a request for payment for example.

> [@pokoli](#):
>
> Normally you receive first the accountant invoice (with the full amount) and then the invoice of the other supplier

I do not see why it is sent in two step. The accountant need to have the supplier invoice to make the payment so he can send the request and the original invoice at once.

---

<div class="post-metadata">

### Author: ![wifasoi](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wifasoi](https://discuss.tryton.org/u/wifasoi)
#### Post date: [August 12, 2019, 9:25am UTC](https://discuss.tryton.org/t/invoice-delegation/1496/16 "2019-08-12T09:25:39Z")

</div>

I think now i can draft a “formal” Feature post with all the element in this discussion. But before that:  
Should this a separate module, or just a new feature of `account_invoice` module?

This modification is a trivial one (and doesn’t disrupt the “invoice” workflow), so i think it can be incorporated in the account\_invoice module. But i want ask for opinion on this.

In each case, the work will be trivial (for me), so don’t factor this in the decision.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 12, 2019, 9:30am UTC](https://discuss.tryton.org/t/invoice-delegation/1496/17 "2019-08-12T09:30:00Z")

</div>

I think it is better to have it in existing modules because it is a feature that may be used by other modules that create invoices.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 11, 2022, 3:23pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/18 "2022-08-11T15:23:49Z")

</div>

For the record this is how SAP is managing it: [https://blogs.sap.com/2020/12/29/alternative-payee-vs-alternative-payee-in-document.-is-it-the-same/](https://blogs.sap.com/2020/12/29/alternative-payee-vs-alternative-payee-in-document.-is-it-the-same/)

---

<div class="post-metadata">

### Author: ![wifasoi](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wifasoi](https://discuss.tryton.org/u/wifasoi)
#### Post date: [August 11, 2022, 6:09pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/19 "2022-08-11T18:09:05Z")

</div>

The example you linked seams to describe a supplier invoice where the supplier what you to pay another supplier on his behalf (If I underatand it correctly).  
So this is opposite of what i was trying to archive:  
Someonw pays an invoice on my behalf, and I owe him money.  
Anyways, I think this can be part of the same module.. because the article drives a compelling usercase (contractor that ask you to pay his invoices on yoir behalf).  
Of couse… I still need to write this thing, after i complete the Association module.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 11, 2022, 9:09pm UTC](https://discuss.tryton.org/t/invoice-delegation/1496/20 "2022-08-11T21:09:53Z")

</div>

Here is [Support alternative payees on invoice (#11646) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue11646)

[Next page](https://discuss.tryton.org/t/invoice-delegation/1496.md?page=2)
