Updating fiield in PostgreSQL table using .update() not working in django - python-3.x

I've been trying to update the invo_payment_method value from a table called Invoices. This is the code that I currently have to try to achieve this:
if total_payments_for_invoice.all().count() == 1:
invoice_object = Invoice.objects.get(slug=slug)
invoice_object.invo_payment_method = request.POST.get('payment_method')
invoice_object.save()
So what I'm trying to do is if it's the first payment for the invoice I want to get invoice_object which has the slug of the invoice that just got a payment and update the invo_payment_method field in the table and save the changes. But that's not working. I also tried doing the following:
if total_payments_for_invoice.all().count() == 1:
Invoice.objects.filter(slug=slug).update(
invo_payment_method=request.POST.get('payment_method'))
And it's not working either. After that I tried adding a the following to the code above:
if total_payments_for_invoice.all().count() == 1:
Invoice.objects.filter(slug=slug).update(
invo_payment_method=request.POST.get('payment_method')).save()
And this one actually updated the value in the database, but it made the webpage crash because of the following exception: AttributeError: 'int' object has no attribute 'save'. In case more information is needed, if I print the value of Invoice.objects.get(slug=slug) I get the following: INV-bb1c 21. And if I print the value of Invoice.objects.filter(slug=slug) I get the following: <QuerySet [<Invoice: INV-bb1c 21>]>. In both cases I'm getting the invoice number which is INV-bb1c and the invoice pid which is 21. Please see image attached of how the Invoice table looks like. Any help would be greatly appreciated. To clarify: invo_payment_method is initially null in the database and request.POST.get('payment_method') returns a string of the payment method used.

Related

Netsuite Invalid API usage. You must use getValue to return the value set with setValue

So I have an odd issue, When I create a new transaction and save, this error in the title gets thrown. But when I edit this transaction after it was created, the getText does not throw this error. Is there something I'm doing wrong or something special needed to getText on a create new record? Here is my code. This is for the afterSubmit method on my User Event Script for Vendor Bill screen. I just noticed getValue does work on create, does not produce this error, just don't understand why? Is this the correct way to get the value on create? To use getValue and getText cannot be used on create? Only for edit?
if (scriptContext.type == scriptContext.UserEventType.CREATE ||
scriptContext.type == scriptContext.UserEventType.EDIT) {
// get bill to index
var Bill = scriptContext.newRecord;
// fails on this call below on create but works on edit
var refno = Bill.getText({ fieldId: 'tranid' });
}
This behavior is described in the API documentation here.
In dynamic mode, you can use getText() without limitation but, in standard mode, limitations exist. In standard mode, you can use this method only in the following cases:
You can use getText() on any field where the script has already used setText().
If you are loading or copying a record, you can use getText on any field except those where the script has already changed the value by using setValue().
Apparently the newRecord object falls under the second criteria. At this point, the object only has values set. tranid will have a value with the transaction's internal ID, but it won't have the transaction name stored. To get the text, you will have to use record.load() to get the full record, or use search.lookupFields() to get just the transaction name.

This row was already applied and cannot be modified

When i run my code in the test environment to test my new code about kudu insert,it reports to me:
This row was already applied and cannot be modified.
I have already tried to debug my code and to see what is the problem in my code , but it is useless
if((map.get(list.get(i))) instanceof Double){
row.addDouble(list.get(i), (Double) map.get(list.get(i)));
//System.out.println("Double type insert succeed : " + list.get(i) + " : " + map.get(list.get(i)));
continue;
}
I want to know what's wrong in my code because in my previous code i can run correct but know it cannot
In the source code ,The class was that PartialRow has a private propertiy:frozen, It's default value was false,but in my code,when i debug in it,i found that value was true,I think this is the reason that cause the program reports to my : This row was alredy applied and cannot be modified ! asking for help .please
Without full stacktrace and the rest of code I can only guess why this is happening.
My guess is because the Insert object on which this row object is created has already inserted to Kudu (using KuduSession.apply) and then you tried to update it using row.addDouble.
If you are unsure about why please see this example of how to insert into Kudu.
KuduSession.apply method is invoked on Insert object on which PartialRow object is created, this will insert the data from all the PartialRow objects created from the Insert object. This can be done only once on one Insert object. After that you create a new Insert object using KuduTable.newInsert()
In your case you should probably create new object of Insert using KuduTable.newInsert() and create a row object on this.

Get data having a maximum attribute from firebase in nodejs

So i am working with firebase in nodejs, there is a "number" attribute in each of my document of a specific table(name generated at runtime). I want to get the data having the attribute "number"'s maximum value.
Here is my sample data:-
-L1GIb7Vyn6Yhd5gghH0
correct: blah
number: 9
question: A sample question
wrong1: blekh
wrong2: blahhh
I have seen answers like "childAdded" and all but all in vain also I can't use .endAt() or startAt() because I don't know the "number"'s value at any time.
My sample code till now is:-
queRef.child(req.session.quiztopicname+req.session.quiztopictype).
orderByChild("number").endAt(9).once("value",function(snapshot){
console.log(snapshot.val());
});
Use limitToLast(1) on your sorted reference/query to only retrieve the greatest value. Bear in mind that if there are multiple children with the same greatest value, you'll still only get one of them. There's more documentation or sorting and filtering here.

Netsuite bug when creating customerdeposit record

Im trying to create a customer deposit record in Netsuite using suitescript 1.0.
The original code I had in place which had been working perfectly up until the 2016.2 release broke it.
The update broke it, in that it would override the value submitted in the payment field and instantly make it the full amount of the sales order from the sales order ID. Which is not what we need it to do.
Original Code
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit');
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
After a reply on the Netsuite user group prompted me to use the {recordmode:'dynamic'} attributes I am getting a strange error..
Test Replacement Function which doesnt work
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit',{recordmode:'dynamic'});
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
The error message Im getting now is
Invalid salesorder reference key 1260 for customer .
The thing I dont get is how it is now considered NULL, when the value is hardcoded into this test script after I apply the {recordmode:'dynamic'} value.
Ive tried a wide variety of things, but as I dont have Netsuite support, its proving to be something I simply cant figure out.
Any hints, suggestions would be greatly appreciated as Ive been on this for several days
When you use dynamic the order you set fields makes a difference. So when you set the sales order prior to setting the customer you are actually getting the error message "Invalid salesorder reference key 1260 for customer blank"
What I do is create the customer deposit like:
var depRec = nlapiCreateRecord('customerdeposit', {entity:soRec.getFieldValue('entity'), salesorder:soId});
also setting the undeposited funds flag seems to be required (but not always for some reason) so since you are supplying an account id also do this:
depRec.setFieldValue('undepfunds', 'F');

Updating the Shipping Carrier on a Netsuite Customer Record

Just as a test to see if it worked on one record I created the following mass update script and it doesn't seem to be updating the record I am telling it to but I get no errors. What am I doing wrong?
function shipCarrier(rec_type) {
var recid=11952;
var cust=nlapiLoadRecord(rec_type, recid);
cust.setFieldValue('shippingcarrier','UPS');
nlapiSubmitRecord(cust);
}
When I change your code to use cust.setFieldText() rather than cust.setFieldValue(), it works for me as a mass update script.
setFieldValue() is looking for the integer ID of the UPS item rather than the text.

Resources