Moodle set module sequence grammatically - module

after managing to add modules to Moodle programmaticaly (see my old question here) I now also need to add the module at a specific place.
Lets take for example a sample course in Moodle, I have:
Section 0
- Module 1
- --> ADD NEW MODULE HERE <--
- Module 2
Section 1
- Module 1
- Module 2
Section 2
So I need to add the new module I create programatically inbetween module 1 and 2 of section 0.
I know that the order of modules come from table mdl_course_sections and its specified in the column sequence where the ids of the modules exist in comma separated values
Is there a function in Moodle that does that? Set the sequence of a section? I don't want to mess with the DB directly.

After I got some help from Moodle community (thanks Sam Chaffee) here is the solution
//...Do stuff to create module object...
// ...
$moduleinfo = add_moduleinfo($newlabel, $section);
//lets get all sections and modules of the course
$coursemodinfo = get_fast_modinfo($course->id, 0, false);
//get all sections of the course
$coursesections = $coursemodinfo->get_sections();
//get the first section, get_section will return an array of sections so I get position 0 to get section 1
$section01 = $coursesections[0];
//get the first module in the section so we can add on top of it
$firstmodid = $section01[0];
//We need to get cm_info for the specific mod
$mod = $coursemodinfo->get_cm($moduleinfo->coursemodule);
//we also need section_info for the section we want to move to
$sectioninfo = $coursemodinfo->get_section_info(0);
//move the newly created module to section 01 but before $firstmodid
moveto_module($mod, $sectioninfo, $firstmodid);

Related

Show whether a module has or not at least 1 baseline

I have a folder with a bunch of formal modules and I want to know which ones have at least 1 baseline. I started trying something like this:
Item icurr
Folder scr = current Folder
Baseline b = baseline(1, 0, null)
for icurr in scr do
{
if( baselineExists(icurr, b) )
{
print name(icurr)
}
}
The problem with this code is that baselineExists() only accepts a Module object as first parameter and when I declare icurr to Module instead of Item the for loop this does not recognize any module.
I think that it easiest to use the for baseline in module loop.
Loop through all your items, either with using for item in folder (Items in sub-folders are not included, you will need a recursive function that loops through all found folders) or using for item in project (which will automatically traverse recursively all contained folders and projects).
For every item, check if it is a (formal) module using if 'Formal' == type i then {}. If so, get a module variable from the item. Usually, I do this using Module m = read (fullName i, false, true); if !null m then....
Then, when you have opened the module, use code like
Baseline b = null
for b in m do {break} // stop loop at first found baseline
if (!null b) {
print "found a baseline in module " fullName(m) ": " major(b) "." minor(b) " ("suffix(b)")\n"
}
Don't forget to close each module after the evaluation or the script will use a lot of memory

Using compute Method for Calculating Values in Odoo Module customization?

My aim is to create a CRM-Lead extension module in Odoo. My modules aim is to add certain more fields to the Lead section in The CRM Odoo module.
I created a module code which is working fine but one problem is that I have a field named percentage in it, which should calculate like
amount * 100 & store in database. So for that I used compute attribute in Model. But its is not calculating the value... I will provide my code below :-
from openerp import models, fields, api
class legacy_sales(models.Model):
_inherit='crm.lead'
legacy_description = fields.Text(string="Comments")
legacy_amount = fields.Float(string="Amount")
legacy_startdate = fields.Date(string="StartDate")
legacy_percentage = fields.Float(compute='_compute_percentage',store=True)
#api.depends('legacy_amount')
def _compute_percentage(self):
self.legacy_percentage = self.legacy_amount * 100
legacy_sales()
Here legacy_percentage is not storing calculated value in database.. please give advice:-
Browse self to set field value:
for record in self:
record.legacy_percentage= record.legacy_amount * 100

Zoho Creator making a custom function for a report

Trying to wrap my head around zoho creator, its not as simple as they make it out to be for building apps… I have an inventory database, and i have four fields that I call to fill a field called Inventory Number (Inv_Num1) –
First Name (First_Name)
Last Name (Last_Name)
Year (Year)
Number (Number)
I have a Custom Function script that I call through a Custom Action in the form report. What I am trying to do is upload a CSV file with 900 entries. Of course, not all of those have those values (first/last/number) so I need to bulk edit all of them. However when I do the bulk edit, the Inv_Num1 field is not updated with the new values. I use the custom action to populate the Inv_Num1 field with the values of the other 4 fields.
Heres is my script:
void onetime.UpdateInv()
{
for each Inventory_Record in Management
{
FN = Inventory_Record.First_Name.subString(0,1);
LN = Inventory_Record.Last_Name.subString(0,1);
YR = Inventory_Record.Year.subString(2,4);
NO = Inventory_Record.Number;
outputstr = FN + LN + YR + NO;
Inventory_Record.Inv_Num1 = outputstr;
}
}
I get this error back when I try to run this function
Error.
Error in executing UpdateInv workflow.
Error in executing For Each Record task.
Error in executing Set Variable task. Unable to update template variable FN.
Error evaluating STRING expression :
Even though there is a First Name for example, it still thinks there is none. This only happens on the fields I changed with Bulk Edit. If I do each one by hand, then the custom action works—but of course then the Inv_Num1 is already updated through my edit on success functions and makes the whole thing moot.
this may be one year late, you might have found the solution but just to highlight, the error u were facing was just due to the null value in first name.
you just have put a null check on each field and u r good to go.
you can generate the inv_number on the time of bulk uploading also by adding null check in the same code on and placing the code on Add> On Submt.( just the part inside the loop )
the Better option would be using a formula field, you just have to put this formula in that formula field and you'll get your inventory_number autogenerated , you can rename the formula_field to Inv Number or whaterver u want.
Since you are using substring directly in year Field, I am assuming the
year field as string.else you would have to user Year.tostring().substring(2,4) & instead of if(Year=="","",...) you have to put if(Year==null , null,...);
so here's the formula
if(First_Name=="","",First_Name.subString(0,1))+if(Last_Name =="","",Last_Name.subString(0,1)) + if(Year=="","",Year.subString(2,4)+Number
Let me know ur response if u implement this.
Without knowing the datatype its difficult to fix, but making the assumption that your Inventory_Record.number is a numeric data item you are adding a string to a number:
The "+" is used for string Concatenation - Joiner but it also adds two numbers together so think "a" + "b" = "ab" for strings but for numbers 1 + 2 = 3.
All good, but when you do "a" + 2 the system doesn't know whether to add or concatenate so gives an error.

Pull info from datapool, increment a value and store the datapool

The application I test has some areas where it requires unique data. Specifically, the application will generate a request number that can only be used once. After my test runs I must manually update my datapool reference for this number. Is there any way using java, that I can get the information stored in my datapool, increase the value by one, and then save the data back to the datapool. This way I can keep rft in sync with my application in regard to this number.
Here is an example how to read a value from the datapool, increment it by 1, and save it back to the datapool. It is an adapted example from the book Software Test Engineering with IBM Rational Functional Tester. The original source code is from chapter 5 (and can be downloaded from the book's homepage).
// some imports
import org.eclipse.hyades.edit.datapool.IDatapoolCell;
import org.eclipse.hyades.edit.datapool.IDatapoolEquivalenceClass;
import org.eclipse.hyades.execution.runtime.datapool.IDatapool;
import org.eclipse.hyades.execution.runtime.datapool.IDatapoolRecord;
int value = dpInt("value");
value++;
java.io.File dpFile = new java.io.File((String) getOption(IOptionName.DATASTORE), "SomeDatapool.rftdp");
IDatapool dp = dpFactory().load(dpFile, true);
IDatapoolEquivalenceClass equivalenceClass = (IDatapoolEquivalenceClass) dp.getEquivalenceClass(dp
.getDefaultEquivalenceClassIndex());
IDatapoolRecord record = equivalenceClass.getRecord(0);
IDatapoolCell cell = (IDatapoolCell) record.getCell(0);
cell.setCellValue(value);
DatapoolFactory factory = DatapoolFactory.get();
factory.save((org.eclipse.hyades.edit.datapool.IDatapool) dp);
I think it is quite a lot of code to simply change one value—maybe it is easier to use some other method like writing the value to a normal text file.

QTP Unable to differentiate Web Table in Application

I am a beginner in QTP and I am working on an application where there are two different web tables displayed.
The second web table is detail description of the first web table so it displays when we select a row in the first web table.
In other words, Each row in the first table is selectable and when selected corresponds to the second web table
Web table 1 contains something like below for a user
RelationShip | Name
Father | AAA
Mother | BBB
Brother | CCC
Sister | DDD
Sister2 | EEE
Web Table 2 Contains detailed information for each row in Web Table 1 as I earlier mentioned. SO for Father, the below table is reflected
Details
Name | AAA
Age | 50
Relationship | Father
and so on
Second User might/might not have brother/sister.
The problem now I am facing is retrieving data from second web table for different entity of first one since all the property of the web table are similar expect the below property
"html ID" which corresponds to - "DetailParty_randomno"
This random number is the one which defines the uniqueness of the second web table, which can be retrieved from the first web table though it isn't found in the properties section when we use the Object spy.
I can see this random number when I view the source code of the page. It's displayed as value entity in the tr tag
Value entity looks like "Party_randomno"
<tr style="background-color:yellow" value="Party_1" onclick="Call peoplehighlight("Party_1")" language="vbscript">
My question is if there a way to retrieve this value for each row and then use it in identifying the second web table?
However I did try to read from second table by hard coding "html id" in webtable property to see if it's being read but it didn't work
So my second question is with respect to the correctness of the below descriptive programming code. Is there something else I need to include/exclude in the WebTable property to find uniqueness.
I also did my research and found that it's useful to use index but I am not aware on how to find the index of a web table? Also the index changes for each user I am searching and hence I need to find the index of the table during run time before using it
BrowserName = Browser("micClass:=Browser").GetROProperty("name")
PageName= Browser("micClass:=Browser").Page("micClass:=Page")GetROProperty("name")
Set desc = Description.Create()
desc("html tag").Value = "tr"
Set Rows = Browser("B").Page("P").Webtable("WT").ChildObjects(desc)
RoCounter = Rows.Count-1
For valuecount = 0 To RoCounter
id= rows(i).Object.GetAttribute("value")
Next
'When the right ID is got, parsing it in the below for WT2 Identification
Set ObjTable = Browser("name:="&Browsername).Page("name:="& Pagename).WebTable("class:=Web_Table", "html id:=Detail"&id)
Update
I was able to get the value from the source code using Motti's code. needed to tweak a little and my descriptive programming had spaces between name and : so the objetct wasn't being recognized. It's solved now.
When looking at the description you gave to your WebTable I find it hard to see what you're trying to achieve. class in QTP is mapped to the html className property are you sure that Web_Table is correct className? Also there is (AFAIK) no class name property in QTP, if you mean the test object type then there's no need to add it since you already said that the object is a WebTable.
To answer your question, in order to add indexing you just add "index:=1" to the smart identification (or in the description if you're using the object repository), note that index is zero based so 1 is the second object that matches the description (if there are more than one, if there is only one the index is ignored).
In order to get the random number you can try something like this (untested)
Set desc = Description.Create()
desc("html tag").Value = "tr"
Set rows = Browser("B").Page("P").WebTable("T").ChildObjects(desc)
For i = 0 To rows.Count - 1
id = rows(i).GetROProperty("value") ' Or whatever you need here
Next