How can I raise an exception, in a button's logic, without having my view out of sync? - openerp-7

In OpenERP 7, when I'm in a Form view and I click a button (different from "Save" button), before processing the button's logic the form attempts to be saved (either created, or written).
If my button runs and finds an unexpected condition (e.g. data and/or state are not valid), an exception is thrown. The concept behind the exception is expected: we programmed where to raise an osv.except_osv, and it raises as expected.
However, when an exception is raised, the view is out of sync (e.g. if the object -e.g. sale.order in my case- has children, and one additional child is created -e.g. sale.order.line- and the button is pressed). The reason behind, is that the view got an exception from processing the button, and so it will not update as always does.
If, after getting an exception, I click any button (even the Save button), this behavior happens:
For the "Discard" button: If -after clicking the button raising the exception- I click "Discard", another exception will be raised: "Uncaught Record not correctly loaded", and the view and its related views will crash until I refresh the browser.
For any other button: If -after clicking the button raising the exception- I click the button, any new element will be created AGAIN. If I create a new sale.order.line and click the exception-raising button, the new entry will be saved and, since the view does not know about it (since it got an exception and never refreshed), clicking any button will try to save the object and its children again (including creating the new elements, again). As conclusion: If I create a new child, and click the exception-raising button N times, and finally a button which does not cause exceptions, I will get N+1 new children (when I only intended one new child).
Question: How can I prevent that? How can I trigger an exception inside a button's behavior (a button with type: object) without getting my view out of sync?

Related

FormGroup still have controls although deleted dynamically

We have angular page with structure of Left bar (Say Component A), Main content (Say Component B)and right side bar (Say Component C).
Under Left bar , we have dynamically added custom controls. Custom control has say 2 textbox (with validations) and a button. There is button called "Delete" under each control so that that control would be deleted if clicked.
Right Side bar has button say "Save" . Once user clicks on it validation do get fired (if applicable) or saves data.
Issue:
Lets Say I have 5 controls on Left side bar. Lets say their names are ctrl01,ctrl02,ctrl03,ctrl04,ctrl05
When I click on delete button of ctrl02 , It gets Deleted. and then FormGroup has only 4 records ctrl01,ctrl03,ctrl04,ctrl05 and so is UI
However when I Delete ctrl03/ctrl04/ctrl05 the object are Deleted from UI but FormGroup still has ctrl01,ctrl02,ctrl03,ctrl04,ctrl05.
So, Application doesn't Save data for ctrl01 as Validation gets fired for controls which are deleted(ctrl03,ctrl04,ctrl05) but still part of FormGroup.
Please note this issue occurs only after Deleting 2nd and onwards controls .For First it works fine.
I also checked if Object holding all these records is properly updated or not after Deleting. It is updating properly. That's why UI shows correct number of Custom controls. Its just FormGroup which is causing this issue.

Cannot access disposed form despite creating it immediately prior

I have a windows form (VB/.NET) that I want to open when I click a particular button. It opens correctly the first time, but after closing it and trying to re-open it I get this error:
"ObjectDisposedException was unhandle: Cannot access a disposed object. Object name: frm8100VI"
Now, I create a new instance of the form right before calling it's show() method, so I don't know how it's disposed:
Dim form as New frm8100VI
form.show()
This code works correctly the first time it's called, but after closing the form once it will not work correctly again, saying the object has been disposed. To close the form all I do is call me.close()
I'm guessing you have your "Dim form as new frm8100VI" located in a space inside another object or in a public space where it never goes out of scope.
Once you have said "form.show", the user has worked with the form, closes the form.
At this point you cannot call "form.Show" again on the same form object (it is disposed).
You MUST reassign "form = New frm8011VI" again before you can call "form.show" (to re-iterate, after it has been disposed show fails)
If your trying to persist the information inside the "form" object then you should not actually close the form; in the form_unload event you show cancel the closing of the form and simply hide the form. If you do that you can call "form.Show" again without issue.

Form sent to back on interaction with menu item

I've got two forms, one being frmMain and the other being frmDatasets. The idea is that frmDatasets is used to manage the application's datasets (it's a program for comparing sorting algorithms).
I have a MenuStrip on frmDatasets with a few items. I just decided to change the Add Dataset item to a drop-down menu with options for loading one from file, or generating one according to certain parameters. All well and good; just add the items, swap some icons around, and change the event handler's signature to handle the right Click event.
Except when I run the program, clicking on the Add Datasets top-level item for the first time sends frmDatasets to the back, displaying an inactive frmMain. Clicking the item again shows the dropdown menu as usual.
If I instead click another top-level menu item, that works just fine. But then simply hovering my mouse over the Add Dataset item causes the 'send to back' thing to happen.
I say "send to back", but it's really just putting it behind frmMain. It remains in front of other windows like Visual Studio and Firefox.
Anyone know what on Earth is going on with this form?
EDIT: If I show frmDatasets as a modal dialog, it stops the whole "sending to back" thing, but I still have to click the menu item twice before it shows the list.
EDIT2: Overriding the onClick event to call mnuAddDatasetDropDown.ShowDropDown removes the double-click issue, but it's only a solution if I keep the form as a modal dialog. Still gets sent to back. Overriding mouseEnter doesn't do anything to solve it.
Setting the TopMost property of frmDatasets from its Design view to 'true' fixed all of the problems I was having. No insight as to what was going on, unfortunately, but if anyone else is having this problem then hopefully it'll work for them too.

Error Closing a Form Through a User Control

In the program I'm writing, there is just one form. I've made a user control visible and it contains several buttons. One of the buttons is supposed to close the form when clicked. I can't find any way to do this without getting the error: "Cannot access a disposed object. Object name: 'ShapeContainer.'" I'm pretty sure I understand the problem; after the form has been closed, the user control no longer exists, so there's an error when Form.Close() (I've tried Form.Dispose() too) has completed and it tries to go back to the code inside the button click event. Does anyone know how I could accomplish closing the form through this user control's button without getting the error?
Okay I'm pretty new to vb but I think if you get rid of the Form.Dispose() & Form.Close then try Me.Close() as you are referring to the current Form that the button control is located on.
You Should have got this error:
(Error 1 'NameSpace_.Form1' cannot refer to itself through its default instance; use 'Me' instead.)

How could my Application form in vb be closing by itself?

I have a form in a Pocket PC app that is set to be the Application form using:
Application.Run(New frmMain())
Somehow this form is getting closed for no reason while working on another form. No closing event is fired and nowhere in my code can you close the main form anyway. It is only closed by clicking the OK button at the top right of the window. When this is clicked, the user is prompted if he/she really wants to close the application. However, this is not occurring either.
Basically, I am on another form which adds a new record to the database. After adding the record the gotFocus event is somehow called for frmMain. When the code in the gotFocus event reaches a reference to a control on the form, there is an exception that states that the object is disposed.
When I bypass the code in the gotFocus event, the application just closes completely. I verify this by checking that it is not running in the device's memory.
I have been stepping through code for 2 hours and I have absolutely no idea why this could be occurring. Anyone possibly have a tip?
This sounds as an exception being raised anywhere. Maybe an exception on another thread? Look at the output window to see what it says.