This is my function. I am able to create a new quatation on clicking a button in my indent form and also able to see the indent sequence in quatation. But I am not able to update product line in indent in purchase order line. Can any1 help me out here..?
#api.multi
def action_rfq(self):
rfq_obj = self.env['purchase.order']
for order in self.product_lines:
rfq_id = rfq_obj.create({
'series': self.name,
'order_line': ({
'product_id': order.product_id.id,
'name': order.name,
'product_qty': order.product_uom_qty,
'product_uom': order.product_uom.id,
'price_unit': order.price_unit,
'date_planned': datetime.now(),
'order_id': order.indent_id.id,
})
})
'product_id': order.product_id.id,
'name': order.name,
'product_qty': order.product_uom_qty,
'product_uom': order.product_uom.id,
'price_unit': order.price_unit,
'date_planned': datetime.now(),
'order_id': order.indent_id.id,
})
})
return rfq_id
Hello Gautam,
It would be late now ,but can be helpfull for others.You want to update product line in indent in purchase order line ...so for updating the order line you have to call the write function and pass the product value like this...
order_line_obj = self.env['purchase.order.line']
first create the obj of purchase .order.line
browse_obj=order_line_obj.browse(int(active_id))
After creating the object call browse object and pass the id of present record
order_line_id=browse_obj.write({'name':hotel_name})
After doing this call the write function with browse object.and doing so your record will be updated.
Related
There is price filtering written in JavaScript in the template. I want to take the price range given in this filter with dajngo and write a filtering function. I couldn't because I don't know JavaScript. How will I do?
So, i want to write a django function that takes the given start and end values and sorts the products accordingly.
main.js
// PRICE SLIDER
var slider = document.getElementById('price-slider');
if (slider) {
noUiSlider.create(slider, {
start: [1, 100],
connect: true,
tooltips: [true, true],
format: {
to: function(value) {
return value.toFixed(2) + '₼';
},
from: function(value) {
return value
}
},
range: {
'min': 1,
'max': 100
}
});
}
I'm not familiar with noUiSlider but you would need to get the from and to values into Django - you can do that either by submitting a form when clicking FILTER or by sending an AJAX request. I presume you would just submit the form in a standard page submission as you aren't familiar with JS (and therefore AJAX).
def your_view(request)
filter_from = request.POST.get('slider_from')
filter_to = request.POST.get('slider_to')
YourModel.objects.filter(value__gte=filter_from, value__lte=filter_to)
...
You will need to replace slider_from and slider_to with the key values that are sent by the slider input in request.POST - this will be the name of the inputs themselves. You can wrap request.POST in a print statement to easily see what these are. It's just a matter of getting the values and passing them into the filter() function of your model.
I have a WTForm that submits its data in JSON format. Say the database is one recipe to many recipe steps.
{
"stepset-0": {
"recipe_step_id": "5",
"recipe_step_name": "step 1",
"recipe_step_temp": "666.0"
},
"stepset-1": {
"recipe_step_id": "6",
"recipe_step_name": "Step 2",
"recipe_step_temp": "57.0"
},
"stepset-2": {
"recipe_step_id": "7",
"recipe_step_name": "Step 3",
"recipe_step_temp": "68.0"
},
"stepset-3": {
"recipe_step_id": "8",
"recipe_step_name": "Step 4",
"recipe_step_temp": "73.0"
}
}
I'm using JS to remove elements from the table, but currently trying to get my head round how to update the data in the recipe_steps table.
The logic should be basically:
Find the steps in the step table that match the recipe.
See if those steps are in the JSON data (match using the id)
Delete anything that isn't in the submitted JSON.
So if I remove the row with recipe_step_id '8', this gets submitted to the route, and the route works out that it isn't in the data, removes it from the db, then processes the rest of the data as per the route.
My current route (showing add/update functions) is thus:
#app.route('/recipe/recipesteps/<int:recipe_id>/update', methods=['GET', 'POST'])
#login_required
def updaterecipesteps(recipe_id):
recipe = Recipe.query.get_or_404(recipe_id)
data = request.form
nested_data = nest_once(data)
for key, val in nested_data.items():
recipe_step_id = val['recipe_step_id']
recipe_step_temp = val['recipe_step_temp']
recipe_step_name = val['recipe_step_name']
recipe_id = recipe
if recipe_step_id:
recipe_step = ReciperecipeSteps.query.get_or_404(recipe_step_id)
recipe_step.name = recipe_step_name
recipe_step.step_temp = recipe_step_temp
db.session.commit()
else:
recipe_step = ReciperecipeSteps(name=recipe_step_name,
step_temp=recipe_step_temp,
recipe_id=recipe_step.recipe_id)
db.session.add(recipe_step)
db.session.commit()
return redirect(url_for('recipe', recipe_id=recipe.id))
The closest I've got to this is this query:
mash_steps = RecipeSteps.query.filter(RecipeSteps.id.not_in([nested_data.recipe_step_id for val in nested_data.items]), RecipeSteps.recipe_id == recipe_id).all()
...but Python won't iterate over the object.
Probably far from the best way of doing this (I'd imagine I could have parsed the JSON data in the query), but this is what I got working:
# Build a list from the step ids
step_id = []
for key, value in nested_data.items():
recipe_step_id = value['recipe_step_id']
step_id.append(recipe_step_id)
# Query matching items that aren't on the list
recipe_steps = RecipeSteps.query.filter(RecipeSteps.id.not_in(step_id), RecipeSteps.recipe_id == recipe.id).all()
# Loop through the results and delete
for m in recipe_steps:
db.session.delete(m)
db.session.commit()
i have two reports cout_materiel_facture_detail_report.xml (detailed report) and cout_materiel_facture_report.xml (simple report) and have a wizard where the user inputs some data and chooses whether he/she wants to print the simple report or the detailed one. Here is the wizard's class:
class CoutMaterielFactureWizard(models.TransientModel):
_name = 'gc.cout_materiel_facture_wizard'
directeur_parc_id = fields.Many2one('hr.employee', string='Directeur Parc')
procedure = fields.Char(string='Procedure')
version = fields.Char(string='Verion')
date_realisation = fields.Date(string='Date realisation')
# is_landscape = fields.Boolean(string='Mode paysage?')
is_detail = fields.Boolean(string='Version simplifiee?')
#api.multi
def do_toggle_print(self):
cout_materiel = self.env['gc.cout_materiel'].browse(self._context.get('active_id', False))
cout_materiel.write({
'directeur_parc_id': self.directeur_parc_id.id
})
# Print the simple report
if not self.is_detail:
return {
'type': 'ir.actions.report.xml',
'name': 'gestion_cout.cout_materiel_facture_report_template',
'report_name': 'gestion_cout.cout_materiel_facture_report_template',
}
# Print the detailed report
else:
sql = "SELECT SUM(h_sup)+SUM(h_exp),SUM(h_im),count(*),SUM(total), famille FROM gc_cout_materiel_line where " \
"cout_materiel_id =%s group by famille "
self.env.cr.execute(sql, (cout_materiel.id,))
results = self.env.cr.fetchall()
if len(results) > 0:
line_ids = []
for nbht, nbhim, qte, prix_total, famille in results:
line_ids.append((0, 0, {
'famille': famille,
'type': 'VA',
'qte': qte,
'nbr_heures': nbht,
'nbr_heures_im': nbhim,
'nbr_jours': 28,
'prix_unitaire': 'VA',
'prix_total': prix_total,
}))
self.env['gc.cout_materiel_facture_temp'].create({
'chantier_name': cout_materiel.chantier_id.name,
'mois_name': cout_materiel.mois_id.name,
'num_annexe': cout_materiel.num_annexe,
'expediteur': cout_materiel.expediteur,
'destinateur': cout_materiel.destinateur,
'application_date': cout_materiel.application_date,
'date_realisation': self.date_realisation,
'directeur_parc_name': self.directeur_parc_id.name,
'procedure': self.procedure,
'version': self.version,
'prix_total_global': cout_materiel.total_global,
'line_ids': line_ids,
})
return {
'type': 'ir.actions.report.xml',
'name': 'gestion_cout.gc_cout_materiel_facture_detail_report_template',
'report_name': 'gestion_cout.gc_cout_materiel_facture_detail_report_template',
}
But i get this error after i hit the print button
I checked out the database and found both reports are present there.
Any help? please!!
Finally i managed to solve my problem!!
Here is what i did:
I created a method in the wizard model which returns a list of objects that i whant to print and linked the wizard to the qweb report.
Then i called the method from the qweb report using object.my_mehtod() in a t-foreach loop, where object represents the wizard.
With this way i am able to create complex reports and print them easily. One can use this method to get data from several tables and organize the data and retur them as a list.
I hope that it will help someone.
Best regards!!
I have a controller action that looks like this
//An action inside itemUserController
def commentItem() {
String comment = params['itemComment']
User user = session['currentUser']
String title = params['title']
def isBook = false, isTVShow = false, isMovie = false
//I do some manips here......
//and finally...
if(isBook)
redirect(controller: "book", action: "show", id: book.id)
if(isMovie)
redirect(controller: "movie", action: "show", id: movie.id)
if(isTVShow)
redirect(controller: "TVShow", action: "show", id: tvShow.id)
}
My problem is testing this, tried in unit tests as well as integration but am having the same error "NullPointerException" in the lines containing redirect (looks like the book, movie and TVShow controllers inside redirect are null and I have no idea on how to inject them as they aren't fields in the controller class).
java.lang.NullPointerException
at ivvq.ItemUserController.$tt__commentItem(ItemUserController.groovy:138)
Here is my part of code in the test class:
when: "User tries to comment an item with an empty comment title and an empty comment text"
itemUserController.session['currentUser'] = user;
itemUserController.params['itemComment'] = ""
itemUserController.params['title'] = ""
itemUserController.params['itemBookId'] = book.id
itemUserController.commentItem()
then: "The user has an error message and the comment isnt posted"
itemUserController.flash.error != ""
Shortly, what I am intending to do is letting a user comment on an item and render the same item commented after comment submission.
NB: I'm on Grails 2.3.11
I've run into similar situations, and ended up changing my style of redirects. Now I use something like this:
redirect(uri: "/controller/action", params: redirectParams)
For your situation the redirect would look like:
redirect(uri: "/book/show", params: [id: book.id])
Note: I didn't test this, but it should be pretty close. The params is just a map of parameters to send to the next method. This has worked for me in all of my unit testing then.
The documentation for the redirect styles is here, if it is helpful.
I am using jquery-tokeninput as an autocomplete to retrieve some objects in my app.
My js code to initialize the autocomplete is this:
function initialize_search(model, input_busca) {
var url = reverse('autocomplete.'+model) + "?tipos[]=almoxarifado&tipos[]=estoque";
var data = $(input_busca).data('tokeninput');
$(input_busca).tokenInput(url, {
hintText: 'Start to type',
preventDuplicates: true,
queryParam: 'name',
noResultsText: 'No results',
searchingText: 'Search',
prePopulate: data
});
}
All I want is to receive the parameter 'tipos[]' in my view, like this:
types = request.GET.getlist('tipos[]')
And receive this:
[u'almoxarifado', u'estoque']
But when i do this, he only gives me the last one and not all the list, in this case:
[u'estoque']
This is how I call the autocomplete function inside the js:
inicializa_busca('endereco', $("#id_enderecos"));
You must be aware that, ajax is to pass small data, check the size of this list, maybe is better an full post submission!