You know about inverse_name parameter, available for One2many fields. It just tells Odoo which is the mandatory Many2one field in the related comodel to know the records to show.
In standard module account, in account.invoice model, there is a Many2one field named move_id. It is related to account.move model and its purpose is to show the journal entry generated for the invoice when this one is validated.
The only thing I want to do is to show in journal entries form (account.move) the invoice (account.invoice) whose validation has generated that journal entry. So it looked easy for me, I have just created the other part of the relationship in account.move model:
invoice_ids = fields.One2many(
comodel_name='account.invoice',
inverse_name='move_id',
string='Invoices whose validation generated this journal entry',
)
The logical between account.invoice and account.move should be 1:1, but for this case I can use 1:N since the One2many is just informative and readonly for users. So this one seemed to work OK, I was able to see the invoice in the journal entry, but after a while I realised that I had destroyed the workflow with that code.
This is what happens now, I describe it with examples:
I create and validate the invoice SALE/INV/00001.
The validation generates the journal entry 2019/00001. I can see this journal entry in the invoice form, and I can see the invoice in the journal entry form (in the One2many I have created). Right.
I pay the invoice, and here is where everything breaks down. The payment generates the journal entry 2019/00002, which is OK, but now, in the invoice SALE/INV/00001, I see this journal entry instead of 2019/00001, which is wrong, and if I go to the form of the journal entry 2019/00001, the One2many field I have created to show the related invoice is empty, whereas the one in the journal entry generated by the payment shows SALE/INV/00001, when it should be empty.
I expected journal entry's invoice_ids field to show only the invoices whose validation generated that journal entry, since move_id in invoices only shows the journal entries generated by validations.
To correct this I have replaced the One2many invoice_ids by the Many2one invoice_id in journal entry, and I fill this in automatically in account.move ORM create method. But this solution does not link old records in the database, and I still do not understand the behaviour of the code described above.
So, does anyone have an explanation for that? I would like to know why inverse_name behaves like that.
After wasting a lot of time filling in the core with log messages, I found my unfortunate problem.
When you pay an invoice through the standard method (clicking on the Register Payment button), a pop-up of the account.payment model is opened. This model has already a field named invoice_ids, and Odoo is using the context of the action which opens the pop-up to fill it in automatically with the current invoice:
<field name="context">{'default_invoice_ids': [(4, active_id, None)]}</field>
When the payment is accepted, a call to account.move create method is done to generate the payment journal entry. The problem is that the context of the action still remains in that call, which means that Odoo thinks that I want to fill in my custom field invoice_ids of account.move with that value (which is always the active id, the invoice we keep opened)... and that is not the truth.
I guess that is very bad luck.
Finally I fixed it just modifying the technical name of my One2many field to avoid Odoo to be confused:
validated_invoice_ids = fields.One2many(
comodel_name='account.invoice',
inverse_name='move_id',
string='Invoices whose validation generated this journal entry',
)
Related
I am trying to create a Journal Transaction of AR module from Shipment screen with new button, on this new button click, it should create Journal Transactions document with credit amount in one account and debit amount in one account, These two accounts are configured in shipment screen only. but am getting below error. I am passing Project and all the other mandatory field values from code.
Error: Inserting 'GL Transaction' record raised at least one error.
Please review the errors. Project is Required but was not specified. Account '40000' used in the GL Transaction is mapped to Project Account Group.
You need to either pass in the project from the shipment (if the journal transaction should hit the project) or pass in the default non project value.
for example if not setting the project from the shipment you can set your project field on the journal lines using the following:
myInTran.ProjectID = ProjectDefaultAttribute.NonProject();
If you are pulling the project from the shipment you need to set the journal tran lines for the ProjectID, TaskID, & CostCodeID fields.
Depending on the version of Acumatica you are using, you might not have CostCodeID. I think it was added in 2018R1.
If using the Non project value, the TaskID and CostCodeID are not required.
2013 On-Premise
Hello,
I have a parent record and a subgrid that can create a related record. When I create this related record several of the parent fields are mapped over to save the user double entry & mistakes.BTW the related record is being created via a quick create form.
Everything works great....at first.
If the parent record changes and the changes are saved. Then a new related record created the mapped fields DO NOT reflect the updated parent?
Further this behavior exist if there are NO related records or several.
Is my relationship not properly defined...i.e. needing cascading?...I thought that was just for cascading deletes???
Any input greatly appreciated
#Dave
My apologies...perhaps I have not been clear or I am not understanding you.
....If you need the previously mapped fields to change when the parent record values change....
This is where I am wondering if I am not being clear or understanding. This is happening on the "create" not existing records.
So I thought perhaps incorrectly if I changed the parent record and then went to create a new related record it would get the new mapping?? BOLD just so text isn't lost between picts.
The mapping functionality is only applied when the child record is created. Cascading only applies to events like deleting, sharing, unsharing, assigning, and re-parenting the parent record. Mapping is not involved in cascading at all. - http://msdn.microsoft.com/en-us/library/gg309412.aspx
If you need the previously mapped fields to change when the parent record values change, this would best be addressed with a plugin. You may also consider making the child's mapped fields read only so user's don't think they can enter information in the child record's fields that get populated from the parent.
I have a custom entity Partnership in which I have one lookup field contacts.
now I want to add the name field value of the partnership from contact fullname in time of creation of Partnership.
is it possible with the help of pre-existing configuration settings,(without plugin or web resource)
Thanks.
Without using a plug-in or web resource you have a couple options.
1- You can configure the mappings between the 2 entities by going to the Entity (contact) -> Relationship -> Mappings -> and add a new mapping there. For this to work though, you will need to create the child record from the subgrid of the contact, and if the contact changes it won't update the values. So it may or may not be an ideal solution for you.
2- You can create a workflow rule that runs on create and/or update of the Partnership record that pulls the value from the parent contact onto the partnership record. The downside of this is that workflows are async so you won't see the update for a few seconds and refresh the Partner record.
Hope this helps.
If you want to be able to click the "New Partnership" button in the CRM ribbon, then select a contact, and have the name of the contact, be used to populate another field on the form, you will have to use JavaScript. There is no configurable way of doing it.
If you'd like the value to be populated before it is saved in the CRM database, you could use JavaScript, or a custom Plugin. If you'd like the value to be updated after the record is created, you could use a workflow.
You'll have to use one of those three methods to populate the field. The real question I have though, is why are you bothering to populate the field in the first place? You can add the full Contact name to any view, so I don't see a real big reason to include it.
In CRM 2011, notes get automatically created and attached to main record on lost focus event. Requirement is to remove this auto save functionality. Only till main form is open user should be able to edit notes. And newly added notes should only get saved once main form is saved. For example, if user add one note and closes the browser or do not save the main form, then that note should not get attached to main record, new note should get discarded.
I was thinking following solution:
create new custom entity TempNotesHolder
Create 1:N relationship with the entity where we want this functionality, for example Case entity
Make actual case's note section read only(it is requirement, user don't want to edit/delete functionality for notes once note get created)
Write plugin for create event of Case and create one Record for TempNotesHolder and associate it with case(RegardingId field in TempNotesHolder = incidentId) This will ensure one Case will always have only one associated TempNotesHolder record. There is no way in CRM 2011 to ensure One entity record will have only one record in associated entity i.e. 1:1 relationship. At least I don't know the way. Let me know if any one are aware about it.
On Case form, add one IFrame below Case's note section
on case form load event, get TempNotesHolderId associated with case using fetchXml.(There is no actual field in Case entity that refer to associated TempNotesHolder, hence need to use fetchXml. Some how we can add associated TempNotesHolderId to Case entity, and place that field on Case form, make it hidden, to avoid fetchXml)
Prepare url to display only notes of TempNotesHolder record.(/_controls/notes/notesdata.aspx?EnableInlineEdit=false&EnableInsert=true&id=&ParentEntity=
Set this url to newly added IFrame, so notes of associated TempNotesHolder get displayed in IFrame. It will also have link "Add New Note".
User can add note to TempNotesHolder which are not directly added to Case record.
Next develop plugin on pre save event of Case and check if there are any notes added to TempNoteHolder, if yes move those notes to Case record, and delete notes for TempNoteHolderId. This way notes will get saved to main record only on main form save.
To handle browser close event after adding few notes to TempNotesHolder, write plugin on Case pre Retrieve event, check if any notes present for associated TempNotesHolderId, if present then delete those notes. (As notes are present on TempNotesHolderId, that means due to some reason these notes are not moved to actual case record and we no longer need them, so delete them. This will ensure on case load, TempNotesHolder note section always be blank)
The above solution was fine till step 8. When I tried to add notes in TempNotesHolder, it gave me error, "Record with does not exists in TempNotesHolder". Then I checked that GUID, I disappointed to know CRM is taking IncidentId when I create note for TempNotesHolder. Then I tracked down the actual code for create notes to find why it is taking IncidentId instead of TempNotesHolderId. I found following code in "_static/_controls/notes/notes.htc" function name "UpdateNote"
xml="0"+CrmEncodeDecode.CrmXmlEncode(value)+""+_parentCrmFormSubmit.crmFormSubmitId.value+""+this.parentEntityType+""+CrmEncodeDecode.CrmXmlEncode(currentTitle)+""+this.userId+""
CRM is taking _parentCrmFormSubmit.crmFormSubmitId.value as objectid while creating note.
Now I stuck with this problem. Any thoughts to overcome this show stopper issue are appreciated. Also any other alternate solution to main requirement are also welcome.
Pravin Pujari (Microsoft Dynamics CRM 2011 Developer)
I would suggest simplifying the solution as follows:
Add a field to Case called new_notetext.
Create a Plugin against the Pre-Create and Pre-Update messages on the Case entity.
In the plugin, take anything entered into new_notetext and add a note to the Case entity using that text. Then clear the field new_notetext so nothing is saved with the record.
Should work just fine and is much simpler to implement.
I work in a development/support team which has a shared Lotus Notes mailbox. We need to be able to associate an issue ID with each email. We started by adding this ID to the subject line (eg. "Something doesn't work [ID12345]"). For performance reasons, our IT dept don't allow indexing of shared mailboxes, so it takes a long time to search for a particular ID.
I decided to add a new ID field, which can be shown as a sortable column in views and folders. I put this field to the visible header (just below 'Subject') in the ($All) view and the ($Inbox) folder, and copied the ($Inbox) design to all the other folders in the database. That much was easy.
My problem is that when we reply or forward, this custom field is not carried over to the new memo, so we have to manually add it again before sending. And of course when the user responds, the field is again missing and must be manually added. I have searched the docs and the internet and haven't found any information on this. Either I have to declare this field as something which persists across replies and forwards, or I have to add a line somewhere which explicitly copies the field contents to the new memo.
fsw,
We do exactly this with our complaint system however our database is indexed although this should not be an issue to you. We created a view that is sorted by ID by extracting just the ID from the subject line, order it by ID and then by date descending. Base it on the $ALL folder view so you get both incoming and sent emails.
We then altered the memo form to include an embedded view single category of the new view that sits above the body which shows all other documents linked to the ticket.
This should avoid having to delve to far into the very complex mail template any further. One thing is to make sure you have a copy of the changes you made and a bit of doco re deploying as you can guarantee that one day your template will be completely overwritten in an upgrade and all your good work will be gone.
As the additional field would have to incorporated into all Memo forms in mail templates in your corporation and as these fields do not easily travel via SMTP, you should stick with the ID in the subject.
What you could do is to parse the subject (#Mid, #Right, ...) in the column formula in the view and only display the ID there (like you did with the additional field).
The other option I envision if having a field is required is to have an agent that processes the incoming message(reply) to have it parse out the issue ID from the subject and write it to the field. You could also do that with queryopen or postopen if running an agent is not possible