Link between Purchase Order and Bill uploaded from SDI
The current algorithm tries to match in this order:
1. Document reference(s) * match(es) one or more purchase orders and the total amounts of the bill and the purchase order(s) match as well.
2. Document reference(s) match(es) one or more purchase orders but the amounts do not match.
3. No document reference, but the vendor and total amount of the bill matches exactly one purchase order.
When we generate a vendor bill from an EDI document (electronic invoice), we do have very accurate information however. Matching can also be line by line, since our vendor bill will contain separate lines.
4. We find all purchase orders matching the vendor bill reference(s)
5. For every vendor bill line (having a unit price), we try looking in our matched purchase orders' lines for the same unit price and a remaining quantity higher than or equal to what is in the vendor bill. If multiple matches are found, we check the name similarity and take the most similar line.
This approach makes that more purchase order lines will be able to get matched when using EDI documents.
* The document reference should be communicated to the supplier who will have to insert this info in the nodo IDdocumento on the XML.


FLOW:
1. You create & confirm your PO.
(Note: Never Create a fattura fornitore manually from Odoo - otherwise, you would have 2 bills (the one coming from SDI and the one you manually created)
NB: feedback to not allow to create fattura fornitore from a PO in Odoo is here: https://www.odoo.com/web#cids=1&menu_id=4720&action=333&active_id=809&model=project.task&view_type=form&id=3527851 )
2. The fattura fornitore/bill arrives with OdooBot in draft from SDI. You will also see attached the XLM
If the link is made, it will appear in the draft status (the link should be almost immediately). Odoo does the match with the PO according to the rules described above in the task.
If the PO matches the total amount & lines of the BILL --> it will appear via smart button & the PO lines are invoiced.
If the PO does not match exactly the amount & lines of the BILL --> to check if also via smart button.