How to create a project sheet via the python SDK - python-2.7

I'm trying to create new project sheets in a folder, however I can't find a way to ensure the sheet is a project sheet.
Here is my code so far:
def create_resource_sheet(name):
""" Create a new resource sheet.
:param name:
:return:
"""
folder_id = get_resource_folder_id()
# TODO: Find and delete existing sheet with this name
resource_sheet = SS.models.Sheet({
'name': name,
# 'gantt_enabled': True, # This was added as an attempt to force it to a project sheet, but error 1032
'columns': [{
'title': 'Task',
'type': 'TEXT_NUMBER',
'primary': True,
'width': 200
}, {
'title': 'Status',
'type': 'PICKLIST',
'options': ['wtg', 'hld', 'ip', 'rdy', 'rev', 'fin', 'omt'], # TODO: Update this list
'width': 180
}, {
'title': '% Complete',
'type': 'TEXT_NUMBER',
'tag': ['GANTT_PERCENT_COMPLETE'],
'width': 85
}, {
'title': 'Assigned To',
'type': 'CONTACT_LIST',
'tag': ['GANTT_ASSIGNED_RESOURCE', 'GANTT_DISPLAY_LABEL'],
'width': 150
}, {
'title': '% Use',
'type': 'TEXT_NUMBER',
'tag': ['GANTT_ALLOCATION'],
'width': 60
}, {
'title': 'Days',
'type': 'DURATION',
'tag': ['GANTT_DURATION'],
'width': 70
}, {
'title': 'Start',
'type': 'ABSTRACT_DATETIME',
'tag': ['CALENDAR_START_DATE', 'GANTT_START_DATE'],
'width': 80
}, {
'title': 'Start',
'type': 'ABSTRACT_DATETIME',
'tag': ['CALENDAR_START_DATE', 'GANTT_START_DATE'],
'width': 80
}, {
'title': 'Finish',
'type': 'ABSTRACT_DATETIME',
'tag': ['CALENDAR_END_DATE', 'GANTT_END_DATE'],
'width': 80
}, {
'title': 'Type',
'type': 'TEXT_NUMBER',
'width': 150
}, {
'title': 'Comments',
'type': 'TEXT_NUMBER',
'width': 700
}
]
})
response = SS.Folders.create_sheet_in_folder(folder_id, resource_sheet)
new_sheet = response.result
return new_sheet
I am getting the following error code:
smartsheet.exceptions.ApiError: {"result": {"shouldRetry": false,
"code": 1142, "name": "ApiError", "errorCode": 1142, "recommendation":
"Do not retry without fixing the problem. ", "message": "Column type
DURATION is reserved for project sheets and may not be manually set on
a column.", "refId": "6gurrzzwhepe", "statusCode": 400}}
Is there a way I can create project sheets from scratch?
I have tried setting gantt_enabled to true but that just triggered a different error, so did setting 'project_settings'.
I have tried creating the sheet with just the primary column, then update_sheet to set project settings, which tells me: To set projectSettings, you must first enable dependencies on the sheet.
I have tried setting dependencies enabled, both directly in the create_sheet and in update_sheet, but both return: The attribute(s) sheet.dependenciesEnabled are not allowed for this operation.
I'm going to keep trying things, but I'm getting out of ideas.

Create the sheet from a template, either using the global project template or a user defined template if you want to customize.
templates = SS.Templates.list_public_templates()
for template in templates.data:
if template.global_template ==
smartsheet.models.enums.GlobalTemplate.PROJECT_SHEET:
break
sheet = smartsheet.models.Sheet({
'name': name,
'from_id': template.id
})
resource_sheet = SS.Folders.create_sheet_in_folder(folder_id, sheet)
If you want to customize create a project sheet using the Smartsheet web UI, make your changes and then Save As Template. Once you have the template, grab the ID from the Properties if you don't want to search for it, or SS.Templates.list_user_created_templates().

You cannot create a new dependency-enabled sheet through the API. You'll need to manually create a template and then use the API to make a copy.

Related

Why do I get invalid unsported format character ' ' error when I don't have any ' ' character in parameter names?

I am trying to create a json schema and validate it using the standard validation base class. I get this error message which I can't tell what it refers to exactly.
Looking at my schema and value I don't see anywhere where I have an empty space in the parameter names and I'm not sure what the index 38 reffers to.
The schema that I provide is:
# value = {'enabled': -1, 'order_index': 0, 'width': 10}
# schema = {
'title': 'The Test column schema',
'type': 'object',
'required': ['enabled', 'order_index', 'width'],
'default': {'enabled': True, 'order_index': 0, 'width': 10},
'properties':
{'enabled':
{'title': 'Enabled',
'description': 'Display of column',
'type': 'boolean'
},
'order_index':
{'title': 'Order Index',
'description': 'Order of column to be displayed',
'type': 'number',
'minimum': 0,
'maximum': 999,
'default': 0
},
'width':
{'title': 'Width',
'description': 'Width of column to be displayed',
'type': 'number',
'minimum': 10,
'maximum': 999,
'default': 30}}}
validate_schema = JSONSchemaValidator(limit_value=schema)
validate_schema(value)
Where JSONSchemaValidator is an inheritor of the Django.BaseValidator
class JSONSchemaValidator(BaseValidator):
def compare(self, a, b):
try:
jsonschema.validate(a, b)
except jsonschema.exceptions.ValidationError as e:
raise ValidationError(
"Failed JSON schema check for %(value). {}".format(str(e)), params={"value": a}
)
As it turns out my error was not in my code but an exception in django failing to format a string.

"The provided key element does not match the schema" when writing into a table in DynamoDB

I followed these aws documents in order to set up my DynamoDB table:
creating table
loading the data into the table
Initially I created the table without any concern and the table structure would look like this:
Name > String
(Primary Key)
Category > String
Threads > Number
Messages > Number
Views > Number
When I tried to load the data, which was given on the 2nd hyperlink above, it throws up an exception saying:
An error occurred (ValidationException) when calling the
BatchWriteItem operation: The provided key element does not match the
schema
I did use the following command via the aws cli:
aws dynamodb batch-write-item --request-items file:///home/kula/Documents/aws/sampledata/Forum.json
This is the json file I'm trying to load, which I copied it from aws.
I also had a look into this ticket, and removed the quotes for numbers but still did not have any luck. Where am I going wrong?
Any help would be appreciated.
I apparently ended up creating python scripts to create table and load data into it.
Creating table:
import boto3
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.create_table(
TableName='users',
KeySchema=[
{
'AttributeName': 'username',
'KeyType': 'HASH'
},
{
'AttributeName': 'last_name',
'KeyType': 'RANGE'
}
],
AttributeDefinitions=[
{
'AttributeName': 'username',
'AttributeType': 'S'
},
{
'AttributeName': 'last_name',
'AttributeType': 'S'
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 1,
'WriteCapacityUnits': 1
}
)
# Wait until the table exists.
table.meta.client.get_waiter('table_exists').wait(TableName='users')
Loading data into the table:
#!/usr/bin/python
import boto3
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.Table('users')
with table.batch_writer() as batch:
batch.put_item(
Item={
'account_type': 'standard_user',
'username': 'johndoe',
'first_name': 'John',
'last_name': 'Doe',
'age': 25,
'address': {
'road': '1 Jefferson Street',
'city': 'Los Angeles',
'state': 'CA',
'zipcode': 90001
}
}
)
batch.put_item(
Item={
'account_type': 'standard_user',
'username': 'bobsmith',
'first_name': 'Bob',
'last_name': 'Smith',
'age': 18,
'address': {
'road': '3 Madison Lane',
'city': 'Louisville',
'state': 'KY',
'zipcode': 40213
}
}
)
batch.put_item(
Item={
'account_type': 'super_user',
'username': 'alicedoe',
'first_name': 'Alice',
'last_name': 'Doe',
'age': 27,
'address': {
'road': '1 Jefferson Street',
'city': 'Los Angeles',
'state': 'CA',
'zipcode': 90001
}
}
)
print(table.creation_date_time)
Hope this helps someone!
I ran into a similar issue when trying to batch insert via aws dynamodb batch-write-item --request-items file://data/sample_services_data.json
It turns out that your primary partition key is case sensitive. In this scenario below, '77' will fail the import. If you change it to 'id' instead of 'Id' it will import without throwing the schema error.
{
"PutRequest": {
"Item": {
"Id": { "S": "77" },
"name": {"S":"Amazon Web Services"},
"language": {"S":"Python"},
"description": {"S":"Awesome super service"}
}
}
},
{
"PutRequest": {
"Item": {
"id": {"S":"99"},
"name": {"S":"Epic Service"},
"language": {"S":"NodeJS"},
"description": {"S":"Awesome epic service"}
}
}
}

Odoo can't open form view from wizard on button click

I have created wizard. And on button click I want to open form view with specific model record id.
#api.multi
def create_order(self):
view = self.env.ref('purchase.purchase_order_form')
context = self.env.context
return {
'name':'Name',
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'purchase.order',
'views': [(view.id, 'form')],
'view_id': view.id,
'res_id': 264,
'context': context,
}
The problem is that on button click I can't open other form view.
If I add 'target': 'new', then on button click on popup window I open form wich I need:
#api.multi
def create_order(self):
view = self.env.ref('purchase.purchase_order_form')
context = self.env.context
return {
'name':'Name',
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'purchase.order',
'views': [(view.id, 'form')],
'view_id': view.id,
'target': 'new',
'res_id': 264,
'context': context,
}
The problem is that on button click I need to open specific form but like popup window.
I tried set 'target': 'inline' or 'target': 'current' but nothing happens..
I think the problem will resides on your param res_id, this is not needed actually. its only return the record of res_id if exists. Any way I give you an valid example. so please try:
return {
'name': _('Compose Email'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(compose_form.id, 'form')],
'view_id': compose_form.id,
'target': 'new',
'context': ctx,
}
What model/record is this being called from? For example, are you adding this to a Sales Order or some other model's form?
If so, you may need to set include the Source Model, such as:
'src_model': 'sale.order',
In the documentation, this is used for launching wizards and may be needed for redirecting the model.
SEE AT THE END OF THE RESPONSE FOR A SIMPLER SOLUTION
I had the same problem but I was able to resolve it. I must say that I am using a old OpenERP version (5.0.14), so maybe it does not work with you.
model_obj = self.pool.get('ir.model.data')
res_id = model_obj.get_object_reference(cursor, uid,
'your_model',
'your_view_id_ref_defined_in_xml')[1]
return {
'name': 'View name, anything you want',
'type': 'ir.actions.act_window',
'res_model': 'view_model',
'domain': "[('id', 'in', {})]".format(ids_to_show),
'view_type': 'form',
'view_id': (res_id, 'View'),
}
Using the question example it will be:
model_obj = self.pool.get('ir.model.data')
res_id = model_obj.get_object_reference(cursor, uid,
'purchase',
'purchase_order_form')[1]
return {
'name': 'View name, anything you want',
'type': 'ir.actions.act_window',
'res_model': 'purchase.order',
'view_type': 'form',
'view_id': (res_id, 'View'),
}
Hope it helps!
SIMPLER SOLUTION
Another, maybe simpler and cleaner solution is to set the view_id to False and set the view that you want to load in the context. You can specify what view you will load for the tree part with 'tree_view_ref' and the form part with 'form_view_ref'.
Here is an example loading a view called custom_stock_tree_view and custom_stock_form_view defined in a module called custom_stock
return {
'name': 'Custom Stocks',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'stock.move',
'view_id': False,
'type': 'ir.actions.act_window',
'context': {
'tree_view_ref':
'custom_stock.custom_stock_tree_view',
'form_view_ref':
'custom_stock.custom_stock_form_view'
}
}
Please, note that the view_id is set to False. Otherwise it will not load the desired view (Thanks to Joan M. Grande, who saw this).

expected singleton error in odoo accounts tree view

data = [{'account_type': u'account_type', 'balance': 3484382.4899999998, 'type': 'report', 'name': u'Assets', 'level': 1}, {'account_type': u'liquidity', 'balance': 87301.78, 'type': 'account', 'name': u'100101 Cash', 'level': 4}, {'account_type': u'liquidity', 'balance': 257350.98, 'type': 'account', 'name': u'100201 HDFC Bank', 'level': 4}]
#api.multi
def account_fun():
for item in data:
return item['balance']
i'm calling that function using compute and getting the error expected singleton. but i want store all the balance from data into the database by one by one. in account.account table in odoo .
balance = field.Float(string="Balance",compute="account_fun")#creating new balance field.
how can i do that.and have to show balance field in list view. thanks,
I am not sure what you are trying to do with that logic, I have just give you idea here how you can do it.
data = [{'account_type': u'account_type', 'balance': 3484382.4899999998, 'type': 'report', 'name': u'Assets', 'level': 1}, {'account_type': u'liquidity', 'balance': 87301.78, 'type': 'account', 'name': u'100101 Cash', 'level': 4}, {'account_type': u'liquidity', 'balance': 257350.98, 'type': 'account', 'name': u'100201 HDFC Bank', 'level': 4}]
#api.multi
def account_fun(self):
for rec in self:
balance =0
for item in data:
balance += item['balance']
rec.balance = balance
balance = field.Float(string="Balance",compute="account_fun")
You are getting this error because in self list of recordset will be
there. In new api there is different way to set the functional field
which I have described above.
#api.multi
def account_fun(self):
data = [{'account_type': u'account_type', 'balance': 3484382.4899999998, 'type': 'report', 'name': u'Assets', 'level': 1}, {'account_type': u'liquidity', 'balance': 87301.78, 'type': 'account', 'name': u'100101 Cash', 'level': 4}, {'account_type': u'liquidity', 'balance': 257350.98, 'type': 'account', 'name': u'100201 HDFC Bank', 'level': 4}]
for rec in self:
for j in range(len(data)):
if rec.code in data[j]['name']:
rec.balance= data[j]['balance']
balance = fields.Float(string="Balance",compute="account_fun")
thanks #Emipro Technologies Pvt. Ltd. ,some what changed your code getting what i want.

Django and Extjs, how to use combo with jsonstore

I want to display an extjs combo with a JsonStore
Server side I use python/Django.
So, this is my combo:
xtype: 'combo',
store: new Ext.data.JsonStore({
url: 'get_peoples',
root: 'data',
totalProperty: 'total',
fields: [
{name: 'name', mapping: 'fields.name'},
{name: 'subname', mapping: 'fields.subname'}
],
autoLoad: true
}),
trigerAction: 'all'
and the views.py server side:
def get_peoples(request):
queryset = People.objects.all()
data = '{"total": %s, "%s": %s}' % \
(queryset.count(), 'data', serializers.serialize('json', queryset))
return HttpResponse(data, mimetype='application/json')
the get_people call give me
{"total": 1, "data": [{"pk": 1, "model": "myapp.people", "fields": {"name": "Paul", "subname": "Di Anno"}}
I think i'm not doing it right, cause my combo doesn't display any item
You need to add displayField and valueField declarations to your ComboBox so that it knows which fields from your store to use for either role. Also, setting autoLoad in the store is not necessary.
new Ext.form.ComboBox({
xtype: 'combo',
store: new Ext.data.JsonStore({
url: 'get_peoples',
root: 'data',
totalProperty: 'total',
fields: [
{name: 'name', mapping: 'fields.name'},
{name: 'subname', mapping: 'fields.subname'}
]
}),
triggerAction: 'all',
// Just guessing at the proper fields here.
// Set them to whatever you wish.
displayField: 'name',
valueField: 'subname'
});