I created a record of crm.lead model through controller, and I also want to upload image or file in log note.
class RequestForQuote(http.Controller):
#route('/form/sinsert', type="http", auth="public", website=True, csrf=True)
def qoute_application_process(self,**kwargs):
values = {}
for field_name, field_value in kwargs.items():
values[field_name] = field_value
internal_notes = values['comment'] + ' , ' +values['commercial_company_name'] + ", " +values['contact_address']+ ' ' +values['contact_city'] +' '+ \
values['contact_state'] +' '+values['zip'] + ', '+ values['meeting_ids']
name = values['first_name'] +' '+values['last_name']
opportunity = request.env['crm.lead'].sudo().create({'name': name ,'date_deadline':values['date'],'email_from':values['email'],
'description':internal_notes,'type':'opportunity'
})
return werkzeug.utils.redirect('/form/thankyou')
enter image description here
To create an internal note, you just need to call self.message_post:
self.message_post(body="Internal note", attachments=[('Image', self.partner_id.image)])
You can read more at mail.thread
Related
I was trying out supabase + nestjs REST API. But for some weird reasons, HTTP trigger is not working.
We wanted to call our API end point whenever INSERT | UPDATE | DELETE operations happen in the table.
We looked into supabase webhook, but since it is still in alpha, we could not use it.
So we thought of using Postgres HTTP extension
Here's the step which i have followed.
create user api_gateway with password 'dummypassword';
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO api_gateway;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO api_gateway;
GRANT USAGE ON SCHEMA public TO api_gateway;
GRANT all ON SCHEMA net TO api_gateway;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO api_gateway;
grant usage ON schema extensions TO api_gateway;
Then i created a table in public schema as follows
create table test(
id uuid PRIMARY KEY not null DEFAULT uuid_generate_v4(),
created_at timestamp with time zone default current_timestamp not null,
name varchar(50)
);
Then i created trigger in following format
CREATE OR REPLACE FUNCTION public.test_post()
returns trigger as $$
declare hres http_response;
declare trigger_payload jsonb;
begin
trigger_payload = jsonb_build_object(
'old_record', OLD,
'record', NEW,
'type', TG_OP,
'table', TG_TABLE_NAME,
'schema', TG_TABLE_SCHEMA
);
select * into hres from http(
(
'POST',
'my rest endpoing',
ARRAY[
http_header('Authorization', concat('Bearer ', 'my token')),
http_header('Content-Type', 'application/json')
],
trigger_payload,
trigger_payload
)::http_request
);
return new;
end;
$$ language plpgsql security definer;
DROP TRIGGER IF EXISTS ON_CREATE_test on "public"."test";
CREATE TRIGGER ON_CREATE_test
AFTER INSERT ON public.test
FOR EACH ROW EXECUTE PROCEDURE public.test_post();
Then i ran the following query
GRANT ALL ON FUNCTION public.publish_to_pubsub() TO api_gateway;
Now, when i manually insert a row into the Test table from supabase dashboard, the trigger executes and the REST api request is made.
But when i connect to supabase from nestjs (using type orm module, api_gateway as user) and make a post request to insert a row into test table, i get following error.
QueryFailedError: type "http_response" does not exist
Detailed log
{
length: 721,
severity: 'ERROR',
code: '42704',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: '16',
internalQuery: '\n' +
'\n' +
'declare hres http_response;\n' +
'declare trigger_payload jsonb;\n' +
'\n' +
'begin\n' +
' trigger_payload = jsonb_build_object(\n' +
" 'old_record', OLD,\n" +
" 'record', NEW,\n" +
" 'type', TG_OP,\n" +
" 'table', TG_TABLE_NAME,\n" +
" 'schema', TG_TABLE_SCHEMA\n" +
' );\n' +
'\n' +
' select * into hres from http(\n' +
' (\n' +
" 'POST',\n" +
" 'https://api***********************************',\n" +
' ARRAY[\n' +
" http_header('Authorization', concat('Bearer ', '')),\n" +
" http_header('Content-Type', 'application/json')\n" +
' ],\n' +
' trigger_payload,\n' +
' trigger_payload\n' +
' )::http_request\n' +
' );\n' +
'\n' +
' return new;\n' +
'end;\n',
where: 'compilation of PL/pgSQL function "test_post" near line 3',
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_type.c',
line: '270',
routine: 'typenameType'
}
Not really sure what the issue is. I am happy to provide any additional information.
Can somebody please help me to understand why the IN() function does not work in any of the below attempts?
DECLARE #Company VARCHAR(50) = ('''ABC''' + ', ' + '''DEF''' + ', ' + '''VEG''' + ', ' + '''HIJ''') --+ WNY, VEG''')
PRINT #Company
PRINT IIF('VEG' IN (#Company), 'TRUE', 'FALSE');
DECLARE #Company2 VARCHAR(50) = ('''ABC, DEF, VEG, HIJ''')
PRINT #Company2
PRINT IIF('VEG' IN (#Company2), 'TRUE', 'FAL
Tried running the command as presented and both IIF()s return false.
In Many2one field I Want view invoice name and invoice ammount_total how add this?
customer_invoice = fields.Many2one('account.invoice', 'Customer Inv', select=True)
Now after open customer_invoice field I view eg. INV/2017/0001, INV/2017/0002 I want INV/2017/0001 100€, INV/2017/0002 200€
Is it possible?
This methode change the default name, just add it in invoice class
#api.multi
def name_get(self):
result = []
for record in self:
name = record.name
if record.ammount_total :
name = record.name + ' ' + str(record.ammount_total)
result.append((record.id, name))
return result
I want use name search but below example not working.
Tag 1 1234
Tag 2 2568
Tag 3 0369
After type 036 I want get Tag 3!
class MyTags(models.Model):
_name = "my.tags"
_description = "Tags"
name = fields.Char(required=True)
color = fields.Integer(string='Color Index')
#api.multi
def name_get(self):
result = []
for record in self:
name = '[' + str(record.color) + ']' + ' ' + record.name
result.append((record.id, name))
return result
#api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
args = args or []
recs = self.browse()
if name:
recs = self.search([('color', '=', name)] + args, limit=limit)
if not recs:
recs = self.search([('name', operator, name)] + args, limit=limit)
return recs.name_get()
Note
Above example work fine after type or scan exactly eg. 0369 return Tag 3, but after type eg. 036 not return.
You have to use the like or ilike operator to get such searches to work. It has to be [('color', 'ilike', name)] then. If you want a more specific search pattern, you could also use =like or =ilike, but i have no example for them right now, so look into Odoo doc to find out, what they are doing.
Edit: it's also helpful to get search wildcards around the search team:
name would be '%' + name + '%' so [('name', 'ilike', '%036%')] should find 0369 tag.
In my scenario, i have a new entity called "new_relations" with 2 fields (account1 and account2) that are both lookups to accounts.
In my accounts form i want to display a grid containing any record with the current account, in any of the 2 lookups, that exists in "new_relations" entity.
I´ve created account A and account B; created 1 record in new_relations with new_relations.account1 = account A and new_relations.account2 = account B.
So, when i open account A or Account B i want to see the record created in new_relations.
I have the following code, unfortunately its only showing the record in Account´s A form in my subgrid...
Can anyone help?
function FilterRelacao(){
var relacoes = document.getElementById("Relacoes");
var account = Xrm.Page.data.entity.getId();
var accountname = Xrm.Page.data.entity.attributes.get("name").getValue();
if(relacoes==null){
setTimeout(function () { FilterRelacao(); }, 2000);
return;
}
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='new_relations'>" +
"<attribute name='new_type' />" +
"<attribute name='new_accountid1' />" +
"<attribute name='new_accountid2' />" +
"<attribute name='new_relationsid' />" +
"<order attribute='new_accountid1' descending='true' />" +
"<filter type='and'>" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"<filter type='or'>" +
"<condition attribute='new_accountid1' operator='eq' uitype='account' uiname='" + accountname+ "' value='" + account + "' />" +
"<condition attribute='new_accountid2' operator='eq' uitype='account' uiname='" + accountname + "' value='" + account + "' />" +
"</filter></filter>" +
"</entity>" +
"</fetch>";
relacoes.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
relacoes.control.SetParameter("effectiveFetchXml", fetchXml); //set the fetch xml to the sub grid
relacoes.control.Refresh(); //refresh the sub grid using the new fetch xml
}
Your fetch XML looks correct to me. When you set up the subgrid did you set "Records" = "All Record Types" in the Data Source section? If you did not then the subgrid will append a condition to your fetchxml so that it returns only records related to the specific relationship that you specified.