How do I use onChange function to reset a field in Odoo11? (Barcode Scan) - odoo

there is a barcode field (type: char) in my module, and it holds the scanned barcode value of a product that scanned by using a barcode scanner. This scanned product will be added to the line field(type: one 2 many) in in the POS order. After this, the barcode field should be get cleared for the next product's barcode. This work in Odoo10 but, it's not working in Odoo11. In Odoo11, for the working of onchange, we have to change the value in that Barcode field and press enter or click on save button and edit. Then it will work. But, I need after the scan, that field should be get cleared.
I have given a piece of code below. Waiting for the right solution. Thanks in Advance. :)
class PosOrder(models.Model):
_inherit = "pos.order"
barcode = fields.Char('Product')
#api.multi
#api.onchange('barcode')
def _onchange_barcode(self):
for record in self:
#my codes
record.barcode = ""
print ("Value in Barcode field is ",record.barcode,". Have nice time")
The above code will print the following line in the terminal:
Value in Barcode field is . Have nice time
It sets the barcode field as blank but, it will not affect in the front end. I have attached a screenshot with this.

Related

Appsmith to change the default value of the Input Box

The Process
I am going to use Appsmith to edit the item price using rest API
The Item List Table
Code
{{menitems.data.content}}
Explanation
From the Image, I have been Displaying my Item with the Edit Button in a table that I got from Rest API
While Clicking I have been showing Item's details and the price to be changed
While Clicking the Edit Price Button
I have been Passing the Price from Table to the javascript object which I have been using storevalue to store the price which I will get the price and show in the popup
Code for Passing Table data to the Javascript Object
{{priceCalculation.openModal(currentRow.pricetype,currentRow.price)}}
Description
I have been passing the price from the table to the popup using the above code
Javascript Object code Open a Modal and storeValue
openModal:(price) => {storeValue("price",price);}
Description
Then in the Javascript object, I have been using storeValue to save in a local storage
The Modal Popup
Explanation
As you can see I have been getting the price from storeValue and adding in the input box's Default Value
In the Popup Price Input
{{appsmith.store.pricebefore}}
Description
From the above code I have been adding the price from the store value
Problem
When I change the text it rolls back the value from the storeValue
For Example
price in storeValue = 300
if I tried to change the price input to = 200
then the input price rolls back to = 300
Solution Tried
in the price Input onTextChanged
{{(function({storeValue("pricebefore",price_before_discount.text);priceCalculation.price_before_change(price_before_discount.text);})()}}
Description
In the above code I have to change the text in storeValue too but it's way too slow if I edit too fast like double clear and add text way fast then it's taking too much time to reflect by the time it reflects it's rolling back the value in storeValue
For Example:
The Text in Input = 12345
if I press double bacspace then it's too slow it only clears one
in the price input onSubmit
If I use this it's working fine on Desktop but on mobile I can't
submit the Input there is no Tick button on keyboard
Conclusion
I just need an alternative using the process of getting the price from the table and putting in the input and allowing the user to edit that input without interference

MS Word: Trying to dynamically update a text field when I change pictures

I create scannable QR codes cards in word for users to report problems. Each time I change the QRCode image, I have to change the Caption under the image to match it to the computer we are labeling. Typing this caption takes time, as 9 cards fit on a single page and each has to be updated when we insert/change the image. I'm trying to figure out how to dynamically change the caption each time I change the picture. I am adding an image as an example below. ANY Help would be appreciated.
enter image description here
I have tried looking at VB to set a label and reference the image filename (which us created with the computer name) and just remove the extension, but I can't figure out how to set the properties for the object and dynamically link them. I have little VB.Net scripting and haven't used it in almost 10 years.
Assumning you need a solution for manual data entry into your 9 cards/labels (even though a mailmerge would work better for bulk card/label creation), if you configure each of them with:
a DISPLAYBARCODE field where your image shows the QR code; and
a text content control where your image shows the serial #,
the following ContentControlOnExit macro, placed in the 'ThisDocument' code module of your document or its template will automatically update the QR code in each label/card to match the serial # whenever its content control is exited.
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
With CCtrl.Range.Cells(1).Range
.Fields(1).Code.Text = "DISPLAYBARCODE " & CCtrl.Range.Text & " QR \q 3"
.Fields.Update
End With
End Sub

Is it possible to reference a listbox in a textbox on the same form?

I have an ID field which can not be autonumbered, and serves as the primary key for a table. When we put a new record in we need the next record to be numbered in one of two sequences that are pre-existing and can not be changed.
I was trying to do this:
=IIf([lst_DeviceType]="Cell Phone",DMax("DeviceNum","tbl_Cell_Tab","DeviceNum < 70000")+1,DMax("DeviceNum","tbl_Cell_Tab")+1)
Inside the field that will be used to create a device number.
What we have are cell phones and tablets, for cellphones the devices start at 10000, and for tablets they start at 70000. What I need to have happen is for a selection from a listbox, "Cell Phone" or "Tablet" to cause the next proper sequence number to be generated. ie. 10125 for "Cell Phone" but 70725 for "Tablet"
The above code returned a #Error
My question is thus two fold : One, is something wrong with my code? I am thinking that I am not properly referencing the listbox, but maybe that isn't it. Or two, can I not do this in the text box itself?
This is the code being used in the text box, I could try an OnUpdate on the form,
Which broke when I tried that using this code it was placed in the OnUpdate for the listbox, because that's the main selector:
If Me.lst_DeviceType = "Cell Phone" Then
Me.txt_DN.Value = DoCmd.RunSQL("SELECT MAX(DeviceNum)+1 FROM tbl_Cell_Tab
WHERE DeviceNum < 70000")
Else
Me.txt_DN.Value = DoCmd.RunSQL("SELECT MAX(DeviceNum)+1 FROM
tbl_Cell_Tab")
End If
Me.txt_DN.Locked = True
but I wonder if that is both the best and easiest way to do it?
Listboxes and comboboxes behave differently.
For a listbox, must include Column index when pulling value from selection: [lst_DeviceType].Column(0)
Then you will need code to save the calculated value. Instead of expression in textbox, bind textbox to ID field and use listbox AfterUpdate event:
If IsNull(Me!ID) Then
Me!ID = IIf(...)
End If
AFAIK, cannot use DoCmd.RunSQL to return a value to a variable. That's what domain aggregate functions are for.

How to hide conditionally custom fields in screen exit? (CMOD)

My task is to customize the Header Details Screen of the ME33K transaction, the goal is to add a box with new fields that should appear only if the Agreement type is the one I defined by using the transaction SPRO (ex: Agreement type ABC).
I started making an enhancement to that screen by using the CMOD transaction, I created a dummy box and field with some hard-coded input value and it's working fine.
My next step would be to make these new fields appear only if the Agreement is of type ABC, but I cannot find the correct approach.
I tried doing some Screen-Loop programming and deactivating the box and/or fields, but the only ones that get deactivated are the standard ones that exist already, the ones I added with the enhancement are not affected.
EDIT :
The enhancement I used was 'MM06E005'.
I wrote the following Screen-Loop code in the include provided in the 'EXIT_SAPMM06E_006' user exit :
loop at screen.
if screen-name = 'CUSTOM_FIELDS'.
screen-active = 0.
modify screen.
endif.
endloop.
The enhancement MM06E005 refers to the subscreen SAPLXM06 0101, that you have created with a box with all your custom screen fields.
To hide your custom screen fields, you must:
Call a PBO (Process Before Output) module, to be done in the flow logic of your subscreen (the one which contains the screen fields):
PROCESS BEFORE OUTPUT.
...
MODULE modify_screen_field_attributes.
...
PROCESS AFTER INPUT.
...
In the include LXM06O01 (preferrably), do this:
MODULE modify_screen_field_attributes OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'CUSTOM_FIELDS'. " name of one screen field
screen-active = 0. " hide the screen field
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDMODULE.

What code to use for Access VBA to allow a form to calculate a text response?

I have a generic access database and would like to get the most out of it.
I have created a form (formData_Header) that contains a sub-form (formData_Sub). The sub-form contains text boxes for items to be inventoried, along with data (numbers) from scans that correspond with these items. Each item will have 2 text boxes (count1 and count2) The header of the form contains text boxes that will be applied to all boxes in the sub-form, such as the values from instrument backgrounds. The background will have 2 text boxes (bkg1 and bkg2).
If I haven't lost you yet, I am wanting to take the background values from the header and the count values from the sub-form and calculate a text response in an other text box or Combo Box located in the sub-form.
i.e.: If bkg1 + bkg2 > count1 + count2then the output is "FAIL"
If bkg1 + bkg2 = count1 + count2then the output is "RE-evaluate"
All else output is "OK"
I have tried to do this multiple ways and each time, I get a random error, or the code does nothing.
Create a custom function that is called from the after update event on each control.
It needs to first check if each control/param has a value in it. If not, return the default "FAIL" value, otherwise use the calcs you show above.
If you put the function in the main form code, use this format to put the result into a subform control:
Me.formData_Sub.Controls("txtResult") = strCalculatedResult
If your code is on the subform, write the result into the control with the usual:
Me.ControlName = strCalculatedResult