Magento How to Add Product attribute of dropdown with Key Value Pair - magento

I tried to add a new "product attribute" of dropdown type filed in Magento, i am able to add my dropdown values, but what i need is to add the dropdown as Key => value pair, these key values are used by NAV System. So, how can we achieve this ??
Let me explain with an example :
S.No Key Value
1 IND India
2 AUS Australia
3 NZ New Zealand
Now, i am able to to insert values(India, Australia, New Zealand,...) ; Now i need to insert Keys ( IND, AUS, NZ,...) Because i have to send these key values to NAV System(ref: http://en.wikipedia.org/wiki/Microsoft_Dynamics_NAV), as we integrated magento with NAV.

This is Magento natural function of Magento.
When you setting values to Magento EAV attribute (Catalog / Attributes / New Attribute / Values (on left)), there are fields named Admin, Default Store view etc...
There you set admin value NZ and for default store view set New Zeland, in export/import value will be saved as NZ. New Zeland will be visible only to customer on frontend.

Related

Setting date value in an Interactive grid based on a page item

I am trying to set a interactive grid column value (which is a date) based on a page item (which is also a date). I have already tried defaulting and using dynamic action set value (jquery seletor) to set item value to the interactive grid column but it does not work how I want it to work.
I have a page item called "P_DEF_DATE" and I want to set a date column in the interactive grid to this value but I want when I change the value in the page item and I click add row on the interactive grid, it must always use whatever value I have in the page item. For example:
P_DEF_DATE = 12-JAN-2021
when I click on add row in the interactive grid, my date column must equal to P_DEF_DATE and i add a few rows based on that date but then i change the date of P_DEF_DATE to:
P_DEF_DATE = 28-JAN-2021
now I want when I click on add row in the interactive grid, I it must show this new date from the page item in the date column in the interactive grid, keeping in mind the page does not refresh and I have rows with the date 12-JAN-2021.
Thank you in advance!
I implemented same few days ago. Following is what I did.
Create Dynamic Action on Row Initialization Event, set Region to your IG
Set True Action to Execute JavaScript Code
Use code
var model = this.data.model,
rec = this.data.record,
meta = model.getRecordMetadata(this.data.recordId);
if ( meta.inserted ) {
model.setValue(rec,"COLUMN_NAME", $v("P_DEF_DATE"));
}
Replace JOB with your column name and P_DEF_DATE with you Item name
More details Here
Also, out of curiosity, why there is no number like P1, P2 in your item name ??

Tableau: How to restrict a dropdown filter to fields that start with "2021*" (a fiscal week field that adds a new field weekly)?

I need an automatic way to have new fiscal weeks (a string that looks like yyyyww) added to my dropdown filter. It's necessary that it's a dropdown unfortunately. Can I just filter out all values that don't start with "2021*" in this particular table? I use those other values in other parts of my dashboard, so I can't filter them out of my data completely.
Create a calculation called DateDisplay as follows:
IF STARTSWITH((STR([Period])),'2021') = TRUE then 'Display'
END
Add the new DateDisplay field to the Filters Shelf and uncheck NULL
Select 'Show Filter' for the string date field
On the drop down menu (down arrow on the right) for the filter which is now showing, select the options 'Only Relevant Values'

How i can show many2one field all records on a form view instead drop down list in odoo 10?

How I can show many2one field all records on a form view instead drop down list in odoo 10.
For example, I have a Product category and Products.
When I select Product category from drop down list then all products belongs to that category shows on form view instead of a drop down list.
Here I assume you have category id like,
category_id = fields.Many2one('product.category', "Product Category")
Add Many2many of product.product field to your model for product records.
product_ids = fields.Many2many('product.product', "Products")
Now you need to define onchange on category_id field like.
#api.onchange('category_id')
def onchange_product_category(self):
if self.category_id:
self.product_ids = [(5,)] # unlink all existing records of product
product_recs = self.env['product.product'].search([('categ_id', '=', self.category_id.id)])
self.product_ids = [(4, x) for x in product_recs] # link the product records of selected category
If you do not want to display your product records in list view you can use widget many2many_tags in the form view like,
<field name="product_ids" widget="many2many_tags"/>
It will work for you.

how to display data in custom table in a form view (Odoo)

I want to make some calculations with product data and display them in a custom table.
Specifically what I want to do is:
1. take a list of products of a particular invoice
2. calculate the percentage of the product price to the total value of the invoice
3. display the custom table with the name of the product and the calculated value
for example:
I have a list of the kind:
[{'name': u'Ipad', 'percentage': 45},
{'name': u'Imac', 'percentage': 20}]
How I can display the result in a notebook page of form view? Maybe I can do this with Qweb templates?, any example?, thanks.

How to show region specific products magento?

how to show products in Magento based on selected state and city? is
there any extension available for this feature? or how can i achieve
this?
You can add one (city) or two (state and city) attributes in product model (by back-office panel).
Your news attributes can be contain the list (in example string with delimiter commas) with the list of state/city where the product is allowed to be sell.
For retrieve your state/city allowed list you can :
<?php
// id product is 12345
// the city allowed list attribute code is 'city_list'
$id = 12345;
$product = Mage::getModel('catalog/product')->load($id);
$cityList = $product->getAttributeText('city_list');
var_dump($cityList);
Output something like this :
string(38) "Los Angeles, New Delhi, Caen, etc, etc"
It's possible that you may be add ->getAttributeToSelect('city_list') after load($id) if the attribute isn't retrieve by catalog/product model.

Resources