Why default lines for One2many fields are not filling in related and default values automatically in Odoo 13? - python-3.x

I have a button in the model sale.order with executes the method action_open_certification_views. This method opens the sale.certification tree view. So the method returns the dictionary of the action which opens the sale.certification views, and I have added the following context to auto-fill in the sale.certification fields (sale_id and line_ids, where line_ids is a One2many field pointing to sale.certification.line):
def action_open_certification_views(self):
...
action['context'] = {
'default_name': 'My Certification',
'default_sale_id': self.id,
'default_line_ids': [
(0, 0, {
'quantity': 5.0,
'sale_line_id': line.id,
}) for line in self.order_line
],
}
return action
When I click on the button, the sale.certification tree view is opened right, and if click on Create button, the context of the action is working well since I see the sale.certification form filled in automatically with the default name My Certification, the right link to sale order, and the same number of certification lines as sale order lines has the sale order. Each of this certification lines has quantity 5.0, and the link to sale order line is right too.
The problem is that the sale.certification.line model has many other fields which are related or which have default values, but these certification lines filled in by default by the action context are not filling in those fields.
For example, there is another field quantity2 in sale.certification.line model, and visible in the view, which always takes by default 1.0. However, the field is empty in all default lines. Same problem with related fields. There are some related fields in the view which take their values through sale_line_id field. These one is filled in OK, but the related fields remain empty. For example, in `sale.certification.line model there is this field:
product_uom = fields.Many2one(
related='sale_line_id.product_uom',
)
In spite of having sale_line_id filled in OK in all lines, they have product_uom empty. Can anyone tell me why? Do I have to specify their values in context too, despite they should have been filled in by theirselves?

Related

PO Line Account selector selection doesn't display in field

I have a customization that overrides the Purchase Order Line Account field drop-down lookup selector on the Purchase Order screen. It populates like I want, but the account selected from the dropdown doesn't display in the grid field after chosen. Here it is:
[PXSelector(
typeof(Search5<Account.accountID,
InnerJoin<PMCostBudget, On<Account.accountGroupID, Equal<PMCostBudget.accountGroupID>>>,
Where2<Where<PMCostBudget.projectID, Equal<Current<POLine.projectID>>, Or<Current<POLine.projectID>, IsNull>>,
And2<Where<PMCostBudget.projectTaskID, Equal<Current<POLine.taskID>>, Or<Current<POLine.taskID>, IsNull>>,
And2<Where<PMCostBudget.costCodeID, Equal<Current<POLine.costCodeID>>, Or<Current<POLine.costCodeID>, IsNull>>,
And<Where<Current<POLine.lineType>, Equal<POLineType.nonStock>, Or<Current<POLine.lineType>, IsNull>>>>>>,
Aggregate<GroupBy<Account.accountID>>,
OrderBy<Asc<Account.accountCD>>>),
DescriptionField = typeof(Account.description),
Filterable = false,
SelectorMode = PXSelectorMode.DisplayModeValue
)]
It basically filters on the line type, project, task, and cost code selected on the same PO line. What am I missing or doing wrong so that the selected AccountCD value will display?
Assuming the rest of your customization properly handled the override and the selector itself works (I think that is what you are saying)... If you need to display AccountCD, you should add SubstituteKey = typeof(Account.accountCD). Without that, the selector is set right now to display the AccountID.
[PXSelector(
typeof(Search5<Account.accountID,
InnerJoin<PMCostBudget, On<Account.accountGroupID, Equal<PMCostBudget.accountGroupID>>>,
Where2<Where<PMCostBudget.projectID, Equal<Current<POLine.projectID>>, Or<Current<POLine.projectID>, IsNull>>,
And2<Where<PMCostBudget.projectTaskID, Equal<Current<POLine.taskID>>, Or<Current<POLine.taskID>, IsNull>>,
And2<Where<PMCostBudget.costCodeID, Equal<Current<POLine.costCodeID>>, Or<Current<POLine.costCodeID>, IsNull>>,
And<Where<Current<POLine.lineType>, Equal<POLineType.nonStock>, Or<Current<POLine.lineType>, IsNull>>>>>>,
Aggregate<GroupBy<Account.accountID>>,
OrderBy<Asc<Account.accountCD>>>),
SubstituteKey = typeof(Account.accountCD),
DescriptionField = typeof(Account.description),
Filterable = false,
SelectorMode = PXSelectorMode.DisplayModeValue
)]
On PXSelector, the first "typeof" is the value to be selected. You can add subsequent typeof() references if you want to designate fields to display in the PXSelector (if your intent is to display an actual selector).
SubstituteKey = typeof(DAC Field) alters the selector's display to show the designated field rather than the actual value. It is very common to select the recordID field and substitute the recordCD field.
DescriptionField displays the field designated after the displayed valued (the specifically selected field or the SubstituteKey field if specified). I could be wrong, but I don't believe this shows when the selector is displayed in a grid. I believe it only applies to form fields, such as if you toggle the grid row to a form view.
Filterable is optional, but it allows you to set filters in the selector, such as when you have a lot of records to retrieve and may want to quickly locate a value. I believe there is some overhead to using it, so setting to false as you did could be a tiny performance gain.
I never used SelectorMode before, so you taught me something new here! If adding SubstituteKey does not resolve your issue, you might try removing the SelectorMode line to see if that resolves your issue. By the way it reads, that could be changing the behavior of the selector from what I would expect.
Acumatica support's suggestion solved my problem. Since the Account id is a segmented key, I needed to manually change the PXSegmentedValue to a PXSelector in the .ASPX to get it to work. I also got it to work without that change by using a PXDimensionSelector instead of a plain PXSelector in the override.
[PXDimensionSelector(AccountAttribute.DimensionName,
typeof(Search5<Account.accountID>...

Kentico Admin - Dynamically Change and SAVE Field Name, Value and Label

For a custom page type, I have a multiple choice form filed as seen in image 1 and 2. I was able to set it up (using jquery) so that when I click on other checkboxes belonging to a another field, the checkbox Label and value of this field is changed accordingly as seen in image 3 - 'Author1', 'Author2', 'Author3' were replaced with something else.
The problem is when I hit the Save button, all of my new label/value are not Saved, but the checkbox value and label return to its original value.
Is there a way to make it so that these checkboxes can accept new value and the new value can be saved. Thanks!
Where does authors values come from? Database? You should be able to use SQL query as data source for multiple choice control. This will allow you to store actual values into database whenever you save a page on the Form tab.
So the idea is to load actual values, replace them with 'AuthorN' and change back to original value when checked.
I've set up an example which might help you. I've created a form with three fields:
FirstAuthor
Type: Integer
Form control: Radio buttons
Data source: SQL Query (select userid,username from cms_user)
Has depending fields: true
SecondAuthor
Type: Integer
Form control: Radio buttons
Data source: SQL Query (select userid,username from cms_user)
Has depending fields: true
OrderedAuthors
Type: Text (1000)
Form control: Label
Default value: {% (if(firstauthor>0) { GlobalObjects.Users.Where("userid="+firstauthor)[0].UserName } else {""}) + ", " + (if(secondauthor>0) {GlobalObjects.Users.Where("userid="+secondauthor)[0].UserName} else {""} #%}
Depends on another field: true
I guess you have a list of authors somewhere in the database so you can just replace CMS_User table with your table. Then all you need to do is to adjust the macro in the third field to give you results you want.

Disable a EditorGrid row when a model attribute has been updated

Here's my request :
I have an EditorGrid which renders some rows based on its associated ListStore.
The ListStore has a collection of instances of my model which has an attribute called "markeAsDeleted" which is updated elsewhere in the UI.
My question is :
How is-it possible to change the rendering of the corresponding row to turn it 'disabled' when my 'markAsDeleted' attribute is 'true' ?
What's I'm expecting is a kind of a rendrer to add to my EditorGrid instance which updates the row as the model attribute is updated.
Thanks
Hiding the column with filtering would be your best best.
If you set store.setMonitoChanges(true); then I believe it will reconise when anything changes that model in the store and fire an storeUpdate from there you could re-Apply your filter (if it doesnt do that automatically anyway);
example
store.addStoreListener(new StoreListener<BaseModelData>() {
public void storeUpdate(StoreEvent<M> se) {
store.applyFilters("");
}
})
edit:
After reading the comments on another answer I notice you are using a Grid filter to filter the columns you could just as easily use addFilter on a store.
example
store.addFilter(new StoreFilter<BaseModelData>() {
public boolean select(Store<T> store, T parent, T item, String property) {
return !item.get("markAsDeleted");
}
});
GXT makes sure that when your Grid's store gets modified, the Grid is re-Rendered. So when other part of your application does update on the model, make sure that the same model gets updated on store EXPLICITLY.
You can use store.remove(), store.removeAll(), store.addAll() to replace the model with the updated one.

How to prevent a user from changing the selected row in an EditorGrid

Is there a way that I can prevent a user from changing the selected row? I was looking for something like a selectedRowChanging event that would either prevent or allow user from selecting a new row.
Kinda depends on how you have things set up...
I have a Grid to which I've added a CheckColumnConfig and RowEditor It's really a window into some DataBase tables. The user can modify any column 'except' the key columns. The user may also Add a new row. I defined 2 ColumConfigs. The EditColumnConfig has the various fileds disabled (i.e. if (column = keyColumn) {textField.disabled(); } the AddColumnConfig has all columns enabled.
Now if the user clicks the checkBox on a row and clicks an 'Add' button I reconfigure the grid with the addColumnModel : rowDataGrid.reconfigure(listStore, addStateColumnModel); When the user clicks the RowEditor 'Save' button I erconfigure the grid back : rowDataGrid.reconfigure(listStore, editStateColumnModel);
I 'spose you could define an uneditable ColumnConfig and swap it in and out. (or... catch the RowEditor 'BeforeEdit' event and disable to row).
That's an idea anyway... hope this helps.
grid.addListener(Events.BeforeEdit, new Listener<GridEvent<MyModel>>(){
#Override
public void handleEvent(GridEvent<MyModel> be) {
//This retrieves the model being edited.
MyModel model = be.getModel();
if (I do not want to edit this model){
be.setCancelled(true);
}
}
});

Cascading list boxes, with multi-select

I wound up modifying the source from a publically posted POC: http://datacogs.com/datablogs/archive/2007/08/26/641.aspx, which is a custom field definition for cascading drop downs. The modifications were to allow parent-child list boxes where a user can multiselect for filtering and selecting the values to be written back to a SharePoint list. I got the parent-child cascading behavior working, but the save operation only takes the first value that is selected from the list box. I changed the base type for the custom field control from "SPFieldText" to "SPMultiLineText", along with changing the FLD_TYPES field definition values from:
Text to Note and this did not work. So, I changed the field control base type to "SPFieldMultiChoice" and the FLD_TYPES to "MultiChoice" and still get the same result, which is only the first value that's selected, writing to the SharePoint list.
Does anyone have any idea how to get a custom field with multiple selections to write those multiple selections to a SharePoint list?
Thanks for taking the time to read through my post.
Cheers,
~Peter
I was able to accomplish this by inheriting from SPFieldLookup and overriding its internal handling of AllowMultipleValues:
In your FLDTYPES_*.xml set <ParentType>LookupMulti</ParentType>
In your extension of SPFieldLookup, be sure to override AllowMultipleValues (always true), FieldValueType (probably typeof(SPFieldLookupValueCollection)) and FieldRenderingControl. I also set base.LookupField = "LinkTitleNoMenu", though in retrospect I'm not sure why. :)
In your field editor control's OnSaveChange(), set the field's Mult value to true.
To set Mult, you can either string manipulation on field.SchemaXml:
string s = field.SchemaXml;
if (s.IndexOf(" Mult=", StringComparison.OrdinalIgnoreCase) < 0)
field.SchemaXml = s.Insert(s.IndexOf("/>", StringComparison.Ordinal), " Mult=\"TRUE\" ");
Or use reflection:
var type = field.GetType();
var mi = type.GetMethod("SetFieldBoolValue", BindingFlags.Instance | BindingFlags.NonPublic);
mi.Invoke(field, new object[] { "Mult", true });
It's been a while, so I might be forgetting something, but that should be most of it.

Resources