I am looking for solution for my problems in checkout. First problem is that I need to make field company ID as required if field "Buy as company" is checked. ID of company checkbox is "wi_as_company". I am try to make it like code bellow, but it makes field "billing_company_wi_id" always as required (also for non-company customers).
add_filter( 'woocommerce_checkout_fields' , 'company_checkbox_and_new_checkout_fields_1', 9999 );
function company_checkbox_and_new_checkout_fields_1( $fields ) {
if (isset($_POST['wi_as_company'])) {
$fields['billing']['billing_company_wi_id']['required'] = false;
} else {
$fields['billing']['billing_company_wi_id']['required'] = true;
}
return $fields;
}
My second problem is that I want to move data (first 8 numbers) automatically from one field to another one and add 2 letters before. One field have this format:
12345678-Y-YY
and I want to move first 8 characters to another field like this:
XX12345678
I will be very grateful for any suggestions.
ANSWER FOR FIRST PROBLEM: If checkbox is checked, then field company ID is required. Write code bellow to your child themes functions.php file and change ID of elements:
wi_as_company is ID of checkbox and
billing_company_wi_id is ID of required field if checkbox is checked
add_action( 'woocommerce_checkout_process', 'afm_validation' );
function afm_validation() {
if ( isset($_POST['wi_as_company']) && isset($_POST['billing_company_wi_id']) && empty($_POST['billing_company_wi_id']) ) {
wc_add_notice( __("Please fill company ID"), "error" );
}
}
ANSWER FOR SECOND PROBLEM: Change in code ID of fields and number of characters to copy. In this case it will copy first 8 characters from "billing_company_wi_tax" to "billing_company_wi_vat" plus it will add letters "XX" before copied text. Insert this function to your child themes functions.php.
add_action( 'wp_footer', 'copy_field', 9999 );
function copy_field() {
global $wp;
if ( is_checkout() ) {
echo '<script> document.getElementById("billing_company_wi_tax").setAttribute("onkeyup","URLChange(this.value);");
function URLChange(titlestr) {
var url=titlestr.replace(/ /g,"-");
url = url.substring(0, 8);
document.getElementsByName("billing_company_wi_vat")[0].value="XX"+url;
}</script>';
}
}
I have the following list:
list = [
"WP1788/1",
"WP1810/1",
"WP1810/2",
"WP1812/1",
"WP1815/1",
"WP1818/1",
"WP1823/1",
"WP1827/1",
"WP1828/1",
"WP1828/2",
"WP1828/3",
"WP1828/4",
"WP1828/5",
"WP1828/6",
"WP1837/1",
"WP1840/1",
"WP1841/1",
"WP1855/1",
"WP1860/1",
"WP1861/1",
"WP1863/1",
"WP1872/1",
"WP1873/1",
"WP1873/2",
"WP1879/1",
"WP1884/1",
"WP1888/1",
"WP1895/1",
"WP1895/2",
"WP1906/1",
"WP1906/2",
"WP1908/1",
"WP1908/2",
"WP1909/1",
"WP1909/2",
"WP1913/1",
"WP1918/1",
"WP1919/1",
"WP1919/2",
"WP1919/3",
"WP1922/1",
"WP1928/1",
"WP1928/3",
"WP1928/4",
"WP1928/5",
"WP1928/6",
"WP1944/1",
"WP1944/2",
"WP1945/1",
"WP1946/1",
"WP1947/1",
"WP1955/1",
"WP1962/1",
"WP1965/1",
"WP1965/2",
"WP1967/1",
"WP1969/1",
"WP1977/1",
"WP1988/1",
"WP1991/1",
"WP1991/5",
"WP1995/1",
"WP2002/1",
"WP2012/1",
"WP2015/1",
"WP2017/1",
"WP2021/1",
"WP2022/1",
"WP2024/1",
"WP2033/1",
"WP2033/2",
"WP2044/1",
"WP2050/1",
"WP1585/1",
"WP1585/2",
"WP1585/4",
"WP1585/5",
"WP1585/6",
"WP1585/7",
"WP1585/8",
"WP1585/9",
"WP1624/103",
"WP1624/105",
"WP1624/108",
"WP1624/109",
"WP1624/118",
"WP1624/119",
"WP1624/120",
"WP1624/121",
"WP1624/123",
"WP1624/129",
"WP1624/130",
"WP1624/137",
"WP1624/145",
"WP1624/165",
"WP1624/83",
"WP1624/85",
"WP1624/91",
"WP1624/93",
"WP1670/1",
"WP1708/10",
"WP1708/12",
"WP1708/13",
"WP1708/14",
"WP1708/15",
"WP1708/17",
"WP1708/20",
"WP1708/22",
"WP1708/26",
"WP1708/27",
"WP1708/28",
"WP1779/26",
"WP1838/1",
"WP1844/1",
"WP1876/1",
"WP1882/1",
]
I would like to select the wps (Wp model) in the database with ID in list, something like:
wps_selected = Wp.objects.filter(ID in list)
and then copy the value from the column working_hours to the column non_profitable and save it to database. Is that possible using ORM. I know how to do it in SQL but I am still a bit comfuased about using ORM
You can do that in a simple for loop:
wps_selected = Wp.objects.filter(ID__in=list)
for wps in wps_selected:
wps.non_profitable = wps.working_hours
wps.save()
You can update in bulk with:
from django.db.models import F
Wp.objects.filter(
ID__in=mylist
).update(non_profitable=F('working_hours'))
Note: Please do not name a variable list, it overrides the reference to the list builtin function [Python-doc]. Use for example mylist.
I have a list of lists called "indexList" below. I'm trying to create a new list that just contains the values from indexList that appear in more than one of the lists contained in indexList. Is there a simple way to do this, or do I need to create a hash or maybe a for loop with a counter?
print(indexList)
[[14132732, 17507054, 20154219, 57866667, 64995031, 73339549, 76622670, 77054124, 88266242, 95011712, 97504763, 105453976, 119673246, 121145411, 122730527, 136408685, 145004137, 153916914, 160541689, 167759940, 194678471], [14035852, 14239713, 14806084, 28600799, 55796354, 77054124, 80085145, 89842020, 105453976, 105615905, 112819974, 141740256, 141741893, 174759505, 175188439, 189388409, 197055847, 1027845469], [14059532, 55196567, 55855922, 66556068, 89842020, 93011066, 95458113, 105431163, 105615905, 110681306, 160016156, 163230536, 164783106, 175188439, 186797934, 191913967, 331858466, 337685623, 1011598174], [11666669, 12927826, 14049967, 17986728, 30613784, 38761955, 49501165, 52663092, 58344403, 65417742, 75290545, 76769480, 80461647, 81348271, 83741632, 95458113, 95869938, 97144680, 97238886, 108444865, 132547936, 137180880, 144814077, 150365263, 164783106, 166136003, 166380144, 167759940, 189388409, 191913967, 206079517, 239840607, 248336776, 332225104, 1003902828, 1006421644], [14205773, 14239713, 19124994, 27306691, 38457025, 64561619, 76622670, 80290444, 89217656, 100959649, 107140360, 151048919, 167759940, 198478294], [], [15951676, 17986728, 19875521, 30613784, 38761955, 39401305, 39977884, 56603666, 56612203, 58344403, 78354186, 78934707, 89892972, 97320117, 106311786, 126649974, 132547936, 144501061, 147452410, 163699000, 163823179, 167759940, 172118849, 176086128, 232340666, 235833558], [11666669, 14236027, 14806084, 15563629, 15683187, 19124994, 20154219, 24741733, 24788445, 27186241, 27306691, 30613784, 31025020, 38457025, 39280718, 55796354, 55879097, 57136468, 57866667, 62554743, 78354186, 79559892, 79727956, 80689158, 81136486, 83065898, 89842020, 90679924, 92248343, 97144680, 97320117, 105615905, 117722840, 121145411, 121817275, 132547936, 136181420, 136755608, 150697319, 151048919, 151795031, 153916914, 157299696, 163466152, 164783106, 167759940, 192654998, 193361704, 276378790, 277316518, 337517789], [], [24707679, 39555826, 59380375, 76003587, 108444865, 122730527, 162992192, 166380144, 172149940, 175188439, 184932536, 235833558, 235906336, 244838688, 247663297, 277319959, 288845420, 292437922, 311590450, 337094084, 337644502]]
I'm going to assume that there are not repeat values in each sub list.
from collections import Counter
from itertools import chain
counts = Counter(chain(*indexList))
repeats = [key for key,value in counts.items() if value>1]
I want to create a GI for Inventory Transaction History Screen (IN405000).
Since the table InventoryTranHistEnqResult isn't present in the database...few of the columns of this screen are taken from INTran Table.
I am not able to find following columns: BegQty, QtyIn, QtyOut, EndQty...
I also tried the following query on database to find these columns
SELECT c.name AS ColName, t.name AS TableName
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE '%EndQty%'
The DAC for these fields is:
enter image description here
Looking at the information behind the page in the page Graph will give you the answers to your question. Inventory Transaction History Screen (IN405000) uses graph InventoryTranHistEnq. The grid in this page uses DAC InventoryTranHistEnqResult in the following view:
PXSelectJoin<InventoryTranHistEnqResult,
CrossJoin<INTran>,
Where<True, Equal<True>>,
OrderBy<Asc<InventoryTranHistEnqResult.gridLineNbr>>> ResultRecords
The ResultsRecords are built dynamically in the inquiry using the following:
protected virtual IEnumerable resultRecords()
{
int startRow = PXView.StartRow;
int totalRows = 0;
decimal? beginQty = null;
List<object> list = InternalResultRecords.View.Select(PXView.Currents, PXView.Parameters, new object[PXView.SortColumns.Length], PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows);
PXView.StartRow = 0;
foreach (PXResult<InventoryTranHistEnqResult> item in list)
{
InventoryTranHistEnqResult it = (InventoryTranHistEnqResult)item;
it.BegQty = beginQty = (beginQty ?? it.BegQty);
decimal? QtyIn = it.QtyIn;
decimal? QtyOut = it.QtyOut;
beginQty += (QtyIn ?? 0m) - (QtyOut ?? 0m);
it.EndQty = beginQty;
}
return list;
}
So i guess the short answer is you cannot use the results of this page for a GI as it is built in the page only. You might want to look into adding what you need to this history page via a customization or make your own version of this page/graph/dac if the information you need is that important.
In the Google Treemap Chart every node has to have a unique id, but two nodes can have the same name (https://groups.google.com/d/msg/google-visualization-api/UDLD-a-0PCM/IwVCGzsWOg8J).
I used the schema from the parent/child demo (http://www.iccube.com/support/documentation/user_guide/schemas_cubes/dim_parentchild.php)
Using the following MDX statement in the treemap works, as long as the names of the nodes are unique:
WITH
MEMBER [parent_name] as IIF( [dim (ALL)].[Hierarchy].currentmember
is [dim (ALL)].[Hierarchy].[ALL],'',
[dim (ALL)]. [Hierarchy].currentmember.parent.name )
SELECT
{[parent_name],[Measures].[value]} on 0,
non empty [dim (ALL)].[Hierarchy].members on 1
FROM
[Cube]
If I added the line to the In-memory table in icCube's schema :
7,4,Spain, 2, 32
but the name Spain is double when rendering the Treemap. To support names a child definition in the GVI table should be something like this:
{v:'uniqueID-Spain', f:'Spain'}
As a workaround you can use the following code that modifies GviTable processing for the google tree widget. Check the example here:
https://drive.google.com/file/d/0B3kSph_LgXizSVhvSm15Q1hIdW8/view?usp=sharing
Report JavaScript:
function consumeEvent( context, event ) {
if (event.name == 'ic3-report-init') {
if(!_.isFunction(ic3.originalProcessGviTable)) {
ic3.originalProcessGviTable = viz.charts.GenericGoogleWidget.prototype.processGviTable
}
viz.charts.GenericGoogleWidget.prototype.processGviTable = function(gviTable){
if(this.props.ic3chartType === "TreeMap") {
gviTable = gviTable || this.gviTable();
var underlying = _.cloneDeep(gviTable.getUnderlyingGviTable());
_.each(underlying.rows, function(row){
// Replace id with parent prefixed
if(_.isObject(row.c[0]) && !_.isString(row.c[0].f)) {
row.c[0].f = row.c[0].v;
if(_.isObject(row.c[0].p) && _.isString(row.c[0].p.mun)) {
row.c[0].v = row.c[0].p.mun;
}
}
});
gviTable = viz.GviTable.fromSnapshot(underlying);
this.startColumnSelection = gviTable.getNumberOfHeaderColumns() - 1;
return viz.charts.toGoogleDataTableOneRowHeader(gviTable);
} else {
return ic3.originalProcessGviTable.apply(this, gviTable);
}
}
}
}
For the query like:
WITH
MEMBER [parent_name] as
IIF( [dim (ALL)].[Hierarchy].currentmember.isAll(),
'',
([dim (ALL)].[Hierarchy].currentmember.parent.uniqueName)
)
SELECT
{[parent_name],[Measures].[value]} on 0,
non empty [dim (ALL)].[Hierarchy].members on 1
FROM
[Cube]
This is a limitation of Google Treemap chart that is using the same column for the id and the label. Besides changing the names to ensure they are unique (e.g. adding the parent) I don't see a workaround to this.
An option would be using another Treemap chart (e.g. one from D3) that has not this limitation.
--- icCube Schema ---
The schema is working (just use , instead of ; as separator )
--- icCube Reporting ---
The issue using Treemap is that you've two rows with the same id (Germany), fiddle
This fiddle is a running example of treemap