Odoo 8/9/10 API, how to create an invoice from a sale order via XMLRPC - odoo-8

I'm developing a ruby application which sends some commands to Odoo via XMLRCP API.
I've been able to create a sale order in this whay
def execute_odoo_command(odoo_model, odoo_command, values)
#models.execute_kw(ODOO_DB, #uid, ODOO_PASSWORD, odoo_model, odoo_command, values)
end
def create_order_sale
order_reference = "SO #{#reference_code}_#{#customer_odoo_id}"
values = {
currency_id: 1,
date_order: Date.today.to_s,
name: order_reference,
payment_term: 1,
partner_id: #customer_odoo_id
}
order_id = execute_odoo_command('sale.order', 'create', [values])
create_sale_order_lines(order_id)
execute_odoo_command('sale.order', 'action_confirm', [order_id])
end
Now, I would launch the invoice creation. I have found a way to do it like this
execute_odoo_command('account.invoice', 'create', [invoice_values(order_reference)])
But, even if the invoice is created, the sale order is stil "open" and I can create another invoice from the Odoo interface clicking on "Create Invoice" button (which is obviously wrong). Is there any way to simulate that action via API?
The debug mode does not show any method in the tooltip.
Any suggestion is appreciated, thank you!

For future googlers. The solution is that I'm using an old API version. the right command call is this one
def create_invoice_from_sale_order(sale_order_id)
sale_order_to_invoice_data = [sale_order_id, {context: {active_ids: sale_order_id}}]
#odoo_rpc_client.execute_odoo_command('sale.order', 'action_invoice_create', sale_order_to_invoice_data)
end

Related

Update ticket Field in zoho desk

I'm a beginner at using Custom Function on the Zoho desk. I'm trying to update a field in the ticket template.
I have 2 fields in the ticket template [KM, COST]. The cost should equal 2*KM. For example, if KM = 100, then Cost = 200.
I created a workflow that works if the KM is updated and attached the following custom function code, but the field doesn't update.
orgId = "718524341";
response = zoho.desk.getRecordById(orgId,"tickets",TicketID,"zohodesk");
cid = response.get('cf_km');
km_cost = cid * 2;
zoho.desk.update(orgId,"tickets",TicketID,{"cf":{"cf_cost":km_cost}},"zohodesk");
The correct API Name for the tickets module in zoho desk is Tickets.
If you still can't get it to work, then try executing the function independent of the workflow with fixed parameters. Make sure to do info response and post the output here.

Oracle APEX - I need help to setup dynamic search filter on IG report

I have an IG region where I disabled the toolbar and created my custom search item.
I want user to be able to type the first three characters of a name on the search item (named P8_SEARCH) and the IG report will only show the name(s) that starts with those 3 characters.
This should happen without clicking any button. The IG report query is shown below:
select member_id, first_name, last_name , address, dob, home_phone, cell_phone,
email_address from member_profile where first_name like '%'||:P8_SEARCH||'%';
I also created dynamic action with key release event and True action Execute JavaScript Code shown below:
var keyPressCount=0;
$("#P8_SEARCH").on("keypress", () => {
if (keyPressCount < 2) {
keyPressCount++;
} else {
$s("P8_SEARCH", apex.item( "P8_SEARCH" ).getValue());
}
})
How can I achieve this without submitting the page? I will appreciate any suggestion. Example:
Set an static_id for your IG region, in the dynamic action add apex.region("yourStaticId").refresh();to your JS code, this will refresh only the region.
something like this:
var keyPressCount=0;
$("#P8_SEARCH").on("keypress", () => {
if (keyPressCount < 2) {
keyPressCount++;
} else {
$s("P8_SEARCH", apex.item( "P8_SEARCH" ).getValue());
apex.region("yourStaticId").refresh();
}
})
If the search items are stored in an associated table, my idea is that you could associate a PL/SQL expression to execute using a Process. This process could be executed on a custom action.
Another idea is that you associate the dynamic action with a hidden button press, and make the JavaScript code click on the button. Then, you can 'simulate' the existence of a trigger for your dynamic action with key release event
What do you think?

Passing id/object from one page/context to another in Phoenix 1.4

I have an Events page that is a list and I want a user to click on a specific Event to create a Request to be invited. I want the Request to be tied to that Event and want Event data (name, location, etc) to show on the new request form page.
Events are one type of "object" and the Requests are another. One Event can have many Requests, but not the other way (so one-to-many). I can do a has_many/belongs_to relationship if that makes it better, or I can simply put an event_id in the Requests - I don't have a preference. This is a Phoenix 1.4 project, nothing special or custom, backed by a PostgreSQL DB.
What I can’t figure out is how to pass the Event, or the event_id, to the New Request form. Most everything in the Phoenix framework is really great, but I can’t figure out the right way to do this one simple thing.
What I have right now is more or less based on the basic guides:
project/lib/project_web/templates/tms/event/index.html.eex (Events list)
<table><tbody><tr><td><%= link event.title, to: Routes.tms_request_path(#conn, :new) %></td></tr></tbody></table>
This goes to
lib/project_web/controllers/request_controller.ex (controller)
def new(conn, _params) do
changeset = TMS.change_request(%Request{})
render(conn, “new.html”, changeset: changeset)
end
This goes to
lib/project/tms.ex (context)
def change_request(%Request{} = request) do
Request.changeset(request, %{})
end
Which goes to
lib/project/tms/request.ex (schema)
def changeset(request, attrs) do
request
|> cast(attrs, [:name, :event_id, :email, :request_count]
|> validate_required([:name, :event_id, :email, :request_count]
lib/project_web/tms/request/new.html is a form with boxes for the attributes of the request
Everything with this works fine right now in that I can click on the link in the Events list and be taken to the New Requests form page and can save the request. Obviously, though there is no ID or association established this way.
Obviously I want to do this the Elixir way and not hack something together. I've tried several different ways to pass event_id around but none of them seem to work, so I know I'm missing something but at this point, I can't figure out what that is.
The event id can be passed through params as:
Routes.request_path(#conn, :new, event_id: event.id) # not tms_request_path
And receive in lib/project_web/controllers/request_controller.ex as event_id parameter in new function:
def new(conn %{"event_id" => event_id}) do
# the even_id can be passed directly to new form
render(conn, “new.html”, event_id: event_id)
end
Then you can acquire event_id in new form as #event_id parameter

How to load initial data into ModelMultipleChoiceField - Django 1.6

I'm creating my first site using Django and having trouble loading initial data into a ModelForm linked to the built in Django group table.
Right now, users can go to a group page and select from an array of groups they would like to join. When they return to the page later, they see the same list of options/checkboxes again with no indication of which groups they already belong to.
I can't figure out how to have the intial group data load into the form, such that if you are already a member of "group 1" for example, that checkbox is already checked. I would also like to have it so that you could uncheck a box, and so when you submit the form you could be leaving some groups and joining others at the same time. Any help appreciated! My code below:
class GroupForm(ModelForm):
groupOptions = forms.ModelMultipleChoiceField(queryset=Group.objects.all(), label = "Choose your groups",
widget=forms.CheckboxSelectMultiple())
class Meta:
model = Group
fields = ['groupOptions']
def groupSelect(request):
if request.method == 'POST':
form = GroupForm (request.POST)
if form.is_valid():
group = form.cleaned_data['groupOptions']
request.user.groups = group
return render (request, 'groups/groupSelect.html' , {'form':form})
else:
form = GroupForm()
return render (request, 'groups/groupSelect.html' , {'form':form})
Took me a few days and some trial and error, but figured this one out on my own. Just needed to modify the second to last line in the code above. The ModelForm loads all available groups as options, and the line below causes the groups the user already belongs to to be checked.
form = GroupForm(initial={ 'groupOptions': request.user.groups.all() })

Grails chained drop down

I'm trying to implement chained drop down boxes using the tutorial here. My classes are not as straight forward as the ones in the tutorial though.
I want to chain the drop down boxes for the create.gsp view in the Load class. Each load belongs to an account from the Account class, and each account belongs to a user from the User class, and each user has several cargo destinations from the Address class.
My goal is to have the cargo destination field up date based on which account is selected.
I am having trouble understanding the AJAX function in the tutorial (step 3), and how it relates to the Grails function (step 4).
Here is the AJAX code:
function respondToSelect(event)
{
new Ajax.Updater("memberSelect",
"/chainedSelect/family/updateSelect",
{method:'get', parameters: {selectedValue : $F("familySelect")} }
);
}
Here is the Grails method:
def updateSelect = {
def familySelected = Family.find("from Family as family where family.surname=:surname", [surname:params.selectedValue])
render (template:"selectMember", model : ['familySelected' : familySelected])
}
If someone could just explain what the third parameter of the AJAX function is doing I think I can figure the Grails part out.
{method:'get', parameters: {selectedValue : $F("account")}}
If someone could just explain what the third parameter of the AJAX
function is doing
The third argument is an object of parameters that get passed to the Updater that tell it how to make the HTTP request to the server.
Make the request an HTTP GET request:
method:'get'
Pass the following named query parameters:
{selectedValue: $F("account")}
$F is a prototype shortcut to retrieve the value of an element. In this case, it's getting the selected value of the DOM element with id account.
This ultimately results in something like the following request:
GET /chainedSelect/family/updateSelect?selectedValue=someValue
Where "someValue" is the currently-selected item in the "account" select list.

Resources