Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
4331 Vues

Odoo 12.0+e-20190816 (Enterprise Edition)


I have added a new res.partner field to POs to allow the user to select a contact person from the selected company.

Python code:

vendor_contact_id = fields.Many2one(        "res.partner",        string="Vendor Contact",        help="This name will appear on the PO, and will be the default recipient of e-mailed POs"    )

XML:

<field name="vendor_contact_id" context="{'default_parent_id': partner_id}" domain="[('parent_id','=',partner_id),('is_company','=',False)]"/> 


My issue is that creating a partner appears to trigger a notification message, and this notification message is using the default_parent_id as the parent_id. This references a non-existent mail.message and blocks creation of the partner due to a foreign key constraint. How can I get the default value to only apply to res.partner and not the resulting mail.message? 

Avatar
Ignorer
Meilleure réponse

You can already choose a CONTACT at a COMPANY to Purchase from.

Have you see the context for partner_id that is setup for creating new Vendors from draft Purchase Orders?

https://i.imgur.com/IlG2CxD.png

Perhaps the block is due to your res.partner being created as a Customer, not a Vendor?

Avatar
Ignorer
Auteur

Hi Ray,

Thanks, I appreciate the help. Let me explain why I added this extra field to see if maybe there was a better way to accomplish this.

I understand that a user can select any contact as the vendor, but this results in a few unwanted results.

First of all, the biggest issues is that if we select the contact person, resulting payment/cheques are made out to that individual rather than to the company. We always want payments to be made out to the parent company.

Secondly, this makes our data a lot more scattered. We want to be able to quickly see how many orders, how much money, etc. has been spent with X vendor, regardless if we sent the PO to contact A, B or C.

I did quickly update my context to ensure the res.partner is being created as a vendor but the error is still the same. It really does look like the root of the issue is that there doesn't appear to be a way to determine which model to apply the default to, so once the default value is defined in a context, that context gets passed along to both the res.partner and the mail.message.

You can disallow creation of the Contact if you need to work around this. Although Bills and Payments are being recorded to individuals instead of the Company, the actual AP is not - it is being recorded against the Company. The field commercial_partner_id (Commercial Entity) is used to facilitate this functionality, so also check for customizations on that field or during Vendor Bill creation (possibly Purchase Order validation). Grouping by Commercial Entity instead of Vendor in your Purchase --> Reporting Menu summarizes orders by the correct Entity. Grouping by Partner Company instead of Partner in your Accounting --> Reporting --> Management --> Invoices summarizes Bills by the correct Entity. The Smart Buttons on Company will show you *all* Purchases and *all* Bills for *all* contacts under the Company. The Vendor Ledger smart button will show you *all* Bills and *all* Payments. If you need Commercial Entity shown on Bills and Payments so you can summarize those, create a related field to partner_id.commercial_partner_id. You can also change the Vendor on the Bill from "Company, Contact" to "Company". You can also customize the payment wizard to show the Partner, allowing users to change it from "Company, Contact" to "Company".

I'd agree with Ray that blocking creation of a contact from here ought to be a simple workaround.

We are having this same exact issue when trying to create a contact from another model. Does anyone have a solution to the issue of it trying to create a chatter message? This seems like a bug.