Odoo 15 - how to populate barcode field with concatenation of another field and sequence? - concatenation

I need your advice to populate field barcode in model employee with concatenation of field location_number in model work_location_id and sequence generated by automated action in odoo 15 ?
I want to automatically generate in the number field an identifier with this particular formatting (such as XX-YYYY-AAAAAAA) where XX is generated from the number assigned to location of taking office of the employee since it is a company with several sites, YYYY is generated from the current year and AAAAAAA is generated from the number of files created
What did I do wrong in my code below ?
if not record.barcode:
XX = env['work.location.id'].get('location.number')
YYYY_AAAAAAA = env['ir.sequence'].next_by_code('matricule_')
record.write({
'barcode': XX + YYYY_AAAAAAA,
})
I need to add location_number as prefix of the sequence...instead of XX

To make it easy : consider using the odoo tools to create a computed field. You can find it this way : in App Settings, switch to debug mode by adding "?debug=1" in your url, reload the page, then go to the new Technical Menu-tab > Fields.
Then click on the "Create" button. And you can create your own computed field (type: Char, in your case). As example :

Related

How can i upsert to multiple external Id's in Salesforce?

I have an Account object in Salesforce and I have an custom field called ExternalText. I have marked the field as and External Id and
"Set this field as the unique record identifier from an external system"
There are 2 accounts that have this field set to a value of E1 in Salesforce.
I want to do an upsert from a csv file using DataLoader and the csv looks something like this:
External Description
E1 Description 1
E1 Description 2
But when i do the upsert i get the error:
ExternalTest: more than one record found for external id field: [<id1>, <id2>]
I would have expected the Description field for both to be updated to Description 1 and then Description 2, so if i view the object in Salesforce the Description field would say Description 2
How can i do this ?
You can't do it like that. Upsert has to find 0 or exactly 1 record with that external id. On 0 it'll try to create, on 1 it'll try to update, anything else - error.
For most normal usages you'll want fields marked as ext id to also be marked unique. If this isn't unique at source - you need different value in your field or bite the bullet, learn SF record IDs and do plain old query + update for example.
There's 1 edge case why ext id doesn't automatically mark field unique but if you rely on that technicality I'd say you have bigger problems. Imagine system where both UK and Germany created customer ID 123 and they want to push it to Salesforce. They both claim they were first and absolutely won't change their unique ID. So the trick is you can pull it off with right sharing rules. Upsert done with user that only sees UK data will work and update only UK customer. As I said - it's a technicality, in a "you think you're clever but you just made admin's job trickier" area.

How to find a MoveTo destination filled by database?

I could need some help with a Anylogic Model.
Model (short): Manufacturing scenario with orders move in a individual route. The workplaces (WP) are dynamical created by simulation start. Their names, quantity and other parameters are stored in a database (excel Import). Also the orders are created according to an import. The Agent population "order" has a collection routing which contains the Workplaces it has to stop in the specific order.
Target: I want a moveTo block in main which finds the next destination of the agent order.
Problem and solution paths:
I set the destination Type to agent and in the Agent field I typed a function agent.getDestination(). This function is in order which returns the next entry of the collection WP destinationName = routing.get(i). With this I get a Datatype error (while run not compiling). I quess it's because the database does not save the entrys as WP Type but only String.
Is there a possiblity to create a collection with agents from an Excel?
After this I tried to use the same getDestination as String an so find via findFirst the WP matching the returned name and return it as WP. WP targetWP = findFirst(wps, w->w.name == destinationName);
Of corse wps (the population of Workplaces) couldn't be found.
How can I search the population?
Maybe with an Agentlink?
I think it is not that difficult but can't find an answer or a solution. As you can tell I'm a beginner... Hope the description is good an someone can help me or give me a hint :)
Thanks
Is there a possiblity to create a collection with agents from an Excel?
Not directly using the collection's properties and, as you've seen, you can't have database (DB) column types which are agent types.1
But this is relatively simple to do directly via Java code (and you can use the Insert Database Query wizard to construct the skeleton code for you).
After this I tried to use the same getDestination as String an so find via findFirst the WP matching the returned name and return it as WP
Yes, this is one approach. If your order details are in Excel/the database, they are presumably referring to workplaces via some String ID (which will be a parameter of the workplace agents you've created from a separate Excel worksheet/database table). You need to use the Java equals method to compare strings though, not == (which is for comparing numbers or whether two objects are the same object).
I want a moveTo block in main which finds the next destination of the agent order
So the general overall solution is
Create a population of Workplace agents (let's say called workplaces in Main) from the DB, each with a String parameter id or similar mapped from a DB column.
Create a population of Order agents (let's say called orders in Main) from the DB and then, in their on-startup action, set up their collection of workplace IDs (type ArrayList, element class String; let's say called workplaceIDsList) using data from another DB table.
Order probably also needs a working variable storing the next index in the list that it needs to go to (so let's say an int variable nextWorkplaceIndex which starts at 0).
Write a function in Main called getWorkplaceByID that has a single String argument id and returns a Workplace. This gets the workplace from the population that matches the ID; a one-line way similar to yours is findFirst(workplaces, w -> w.id.equals(id)).
The MoveTo block (which I presume is in Main) needs to move the Order to an agent defined by getWorkplaceByID(agent.workplaceIDsList.get(nextWorkplaceIndex++)). (The ++ bit increments the index after evaluating the expression so it is ready for the next workplace to go to.)
For populating the collection, you'd have two tables, something like the below (assuming using strings as IDs for workplaces and orders):
orders table: columns for parameters of your orders (including some String id column) other than the workplace-list. (Create one Order agent per row.)
order_workplaces table: columns order_id, sequence_num and workplace_id (so with multiple rows specifying the sequence of workplace IDs for an order ID).
In the On startup action of Order, set up the skeleton query code via the Insert Database Query wizard as below (where we want to loop through all rows for this order's ID and do something --- we'll change the skeleton code to add entries to the collection instead of just printing stuff via traceln like the skeleton code does).
Then we edit the skeleton code to look like the below. (Note we add an orderBy clause to the initial query so we ensure we get the rows in ascending sequence number order.)
List<Tuple> rows = selectFrom(order_workplaces)
.where(order_workplaces.order_id.eq(id))
.orderBy(order_workplaces.sequence_num.asc())
.list();
for (Tuple row : rows) {
workplaceIDsList.add(row.get(order_workplaces.workplace_id));
}
1 The AnyLogic database is a normal relational database --- HSQLDB in fact --- and databases only understand their own specific data types like VARCHAR, with AnyLogic and the libraries it uses translating these to Java types like String. In the user interface, AnyLogic makes it look like you set the column types as int, String, etc. but these are really the Java types that the columns' contents will ultimately be translated into.
AnyLogic does support columns which have option list types (and the special Code type column for columns containing executable Java code) but these are special cases using special logic under the covers to translate the column data (which is ultimately still a string of characters) into the appropriate option list instance or (for Code columns) into compiled-on-the-fly-and-then-executed Java).
Welcome to Stack Overflow :) To create a Population via Excel Import you have to create a method and call Code like this. You also need an empty Population.
int n = excelFile.getLastRowNum(YOUR_SHEET_NAME);
for(int i = FIRST_ROW; i <= n; i++){
String name = excelFile.getCellStringValue(YOUR_SHEET_NAME, i, 1);
double SEC_PARAMETER_TO_READ= excelFile.getCellNumericValue(YOUR_SHEET_NAME, i, 2);
WP workplace = add_wps(name, SEC_PARAMETER_TO_READ);
}
Now if you want to get a workplace by name, you have to create a method similar to your try.
Functionbody:
WP workplaceToFind = wps.findFirst(w -> w.name.equals(destinationName));
if(workplaceToFind != null){
//do what ever you want
}

MS Access 2003 - Auto fill form-field based on previous form field.

I am currently attempting to design a database that requires a number of users inputting data via forms.
one of these tables is a 'user' table. Amongst the information in the table is
userid (int),
username (text),
first name (text),
last name (text)
In the even that I'm filling out a form and supply the the username in the username field is it possible if the username already exists to pull the first name and last name from the user table and auto-populate those form fields? If so can you point me in the right direction please?
Directly via access functionality or via vba? If not possible in 2003 is this possible in 2007?
Ok now for the auto fill (yes i did find one example), This will fill the username after you filled the userid (Both should be comboboxes in this case called Usernamecombo and useridcombo)
First make the query with a SQL similar to this:
SELECT [User].username FROM User WHERE ((([User].userid) Like '*' & [Forms]![Yourform]![useridcombo] & '*'));
Lets call this query "qry_username".
Then go to designview of the form and to the properties of the useridcombo, in the event/afterupdate property you make a event procedure (VBA) :
Private Sub useridcombo_AfterUpdate()
[Forms]![yourform]![Usernamecombo].Value = DFirst("username", "qry_username")
Forms("yourform").[Usernamecombo].Requery 'this last line is optional
End sub
Other fields can be added to the VBA pretty simply(dont forget the query)
Private Sub useridcombo_AfterUpdate()
[Forms]![yourform]![Usernamecombo].Value = DFirst("username", "qry_username")
[Forms]![yourform]![Firstnamecombo].Value = DFirst("Firstname", "qry_username")
[Forms]![yourform]![Lastnamecombo].Value = DFirst("Lastname", "qry_username")
Forms("yourform").[Usernamecombo].Requery 'this last line is optional
End sub
I have a similar form and i use to make these field as Comboboxes.
Then set the property row source as a query.
Set the criteria Where like this
WHERE ((([Users].Username) Like '*' & [Forms]![YourForm]![Username] & '*'));
This will allow the user to choose the name as fast as possible
But it will not fill it automatically because my users can have the same username as others.

(VB2010 and ms Access) creating the query using INNERJOIN, select a field, and put the result as Display Member of combobox

before asking i wanna to show my tables and their relationships(created with ms access 2007)
here is the schema :
https://plus.google.com/photos/113802558354450440804/albums/5988059068393888337/5988059068667446962?banner=pwa&pid=5988059068667446962&oid=113802558354450440804
in this case, i create 3 combo boxes in VB2010 :
cbx_major(binded to MAJOR table)|major_id as the VALUE MEMBER, major_name as DISPLAY MEMBER
cbx_student(binded to STUDENT table)|student_id as the VALUE MEMBER, student_name as DISPLAY MEMBER
cbx_course( this is the question )
And here is the scenario :
first, i must choose what major is at cbx_major
second, the cbx_student will instruct the STUDENT table to select the student_name where major is equal to the selected value of cbx_major and set that query result as the DISPLAY MEMBER of cbx_student(this is done succesfuly without writing any code )
(this is the question)then the last, i want to set the cbx_course to display the course_name where student_id is equal to cbx_student.
i have done a lot of effort to do this :
i opened the combobox tasks menu and choose the student_course table and trying to create the query but it results "the schema returned by the new query differs from the base query"
i created the query in access by Joinning the table STUDENT_COURSE and COURSE using INNER JOIN then i bind the cbx_course to that query but it results wrong display.
i opened the xsd file then i create the query there but results wrong result
all those effort does not work.
i want to solve this case without writing code but using a technique such setting the taskbar menu, is it possible ? any idea? thanks so much for the attention

Salesforce Junction Objects

To all salesforce experts i need some assistance. I have my contacts and a custom object named programs. I created a junction object using to master detail relationships with contacts and programs. I want to avoid relating the same contact to the same program. I tried triggers but I couldn't create the testing part to use it outside sandbox.
I went back to the basics and created a Unique text field. I tried to use default value but EVERYTHING i write in that crap is wrong -_-. I tried Contact__r.Email & "-" & Program__r.Name but to no avail.
I tried workflow rules with a field update but my field update NEVER runs.(Yes I did activate the workflow rule) and I didn't know what to write in my rule's code.
The workflow firing condition could be simply a formula that says true. Alternatively use "every time record is inserted". It also depends whether your master-details are set once and that's it or they will be "reparentable" (option introduced in Summer '12 I think). Maybe post a screenshot / text description of your firing condition? Also - is your unique field set to "case sensitive"?
As for the formula to populate the unique field - something like Contact__c + ' ' + Program__c (or whatever the API names of your fields are) should be OK. Don't use Contact__r.Email etc as these don't have to be unique...
You'll have to somehow fill in the uniqueness criteria for all existing records (maybe that's why you claimed it doesn't work?). If you can use Apex for data fixes - something like this should get you started.
List<Junction__c> junctions = [SELECT Contact__c, Program__c
FROM Junction__c
WHERE Unique_Text_Field__c = null
LIMIT 10000];
for(Junction__c j : junctions){
String key = String.valueOf(j.Contact__c).left(15) + ' ' + String.valueOf(j.Program__c).left(15);
j.Unique_Text_Field__c = key;
}
update junctions;
Keep rerunning it until it starts to show 0 rows processed. The Ids are cut down to 15 chars because in Apex you'd usually see full 18-char Id but workflows use 15-char versions.

Resources