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).
Related
I want to put this response in swagger doc too! I use drf_yasg app in django. I've written this code:
#swagger_auto_schema(method='post', request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'login_id': openapi.Schema(type=openapi.TYPE_STRING, description='ID'),
'password': openapi.Schema(type=openapi.TYPE_STRING, description='password'),
}
))
The current swagger_auto_schema property is
{
"login_id": "admin",
"password": "1234",
}
I want to make swagger_auto_schema in the format below
{
"User": {
"login_id": "admin",
"password": "1234",
}
}
I don't know how to provide json data
You need to define the "User" wrapper explicitly in your schema:
#swagger_auto_schema(method='post', request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'User': openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'login_id': openapi.Schema(type=openapi.TYPE_STRING, description='ID'),
'password': openapi.Schema(type=openapi.TYPE_STRING, description='password'),
}
)
}
))
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.
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.
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.
How to index nested documents using Boto into dynamo? Or is it even possible?
I tried the following but it just hangs...
CASE A
users.put_item(data={
'username': 'johnd',
'first_name': 'John',
'last_name': 'Doe',
'account': {'type': 'standard', 'age', '5'},
})
Along the same vein of nesting:
CASE B
users.put_item(data={
'username': 'johnd',
'first_name': 'John',
'last_name': 'Doe',
'account': {'type': {'level':1, 'class':'standard''}},
})
Can it support arrays?
CASE C
users.put_item(data={
'username': 'johnd',
'first_name': 'John',
'last_name': 'Doe',
'accounts': [{'account_name': 1}, {'account_name': 2}]
})
Can it support nested arrays?
CASE D
users.put_item(data={
'username': 'johnd',
'first_name': 'John',
'last_name': 'Doe',
'accounts': [{'account_name': 1, 'types':['Checking']}, {'account_name': 2, 'types':['Savings Standard', 'Savings Plus']}]
})
If not, are there alternatives in or outside of python? Or is this not possible?
You can use the layer1 interface in boto to put nested structures. I'm not sure if it's available in the layer2 interface yet. There's an example in this thread on the AWS forums.