SDD Payment via Automated Action (Odoo v13) - python-3.x

Unfortunately Odoo has removed the automatic SSD payment from v12 to v13, which is crucial for me. Therefore I try to reproduce the behavior via an automated action and came quite far I guess.
I created an Automated Action that watches all invoices in draft and runs a python code if the invoice is set from draft to not draft. But unfortunately I get an error as soon as I try to post an invoice:
"Database fetch misses ids (('10',)) and has extra ids ((10,)), may be caused by a type incoherence in a previous request"
As far as I know this is related to type transformation, but as I am new to python & odoo, I am not sure how to transform the odoo datatypes correctly. Does anyone have a hint?
Here's the python code that should be executed:
payment = env['account.payment'].create({
'payment_method_id' : '6',
'partner_id': record.partner_id.id,
'journal_id' : '10',
'amount' : record.amount_residual
})
The ids are double checked and link to the correct entries:
payment_method_id '6' = my bank account
journal_id '10' = SDD Payment
Below please find the current domain applied to the Automated Action.
Any hints or help is much appreciated!
Many thanks.
Best regards,
Christian

CBfac
On the many2one field you have to assign the ID.
Code Correction:
payment = env['account.payment'].create({
'payment_method_id' : 6,
'partner_id': record.partner_id.id,
'journal_id' : 10,
'amount' : record.amount_residual
})

For everyone who needs automatic SDD payments in Odoo v13, here's the Automated Action that works for me (one more, thanks #Dipen Sah for your assistance):
Modell: account.move
Trigger: on update
Action: Execute python code
Domain (before update):
["&","&","&","&",["sdd_paying_mandate_id","=",False],["partner_id.sdd_mandate_ids","!=",False],["type","=","out_invoice"],["invoice_payment_state","=","not_paid"],["state","=","draft"]]
Domain (after update):
["&","&","&","&",["sdd_paying_mandate_id","=",False],["partner_id.sdd_mandate_ids","!=",False],["type","=","out_invoice"],["invoice_payment_state","=","not_paid"],["state","!=","draft"]]
Python code to execute:
payment = env['account.payment'].create({
#'name' : env['ir.sequence'].next_by_code('account.payment.customer.invoice'),
#'payment_type': 'inbound',
#'partner_type' : 'customer',
'payment_method_id' : 6,
'partner_id': record.partner_id.id,
'journal_id' : 10,
'amount' : record.amount_residual}).post()
You have to upate the journal and payment_method ids within the python code to match your IDs in order to get the action running properly.
Any improvements and/or feedback are welcome.
Best regards,
Christian

Related

NetSuite SuiteScript 1.0: Cannot save quote in RESTlet

So I'm trying to create an estimate (quote) within NetSuite using SuiteScript 1.0.
I have been following this example provided from NetSuite's help centre:
Example 1
The following example creates an estimate with two items.
var record = nlapiCreateRecord('estimate');
record.setFieldValue('entity', 79);
record.setFieldValue('memo', 'Estimate Memo' );
record.setLineItemValue('item', 'item', 1, 21);
record.setLineItemValue('item', 'quantity', 1, 10 );
record.setLineItemValue('item', 'price', 1, 1 );
record.setLineItemValue('item', 'item', 2, 21);
record.setLineItemValue('item', 'quantity', 2, 5 );
record.setLineItemValue('item', 'price', 2, 2 );
var id = nlapiSubmitRecord(record, true);
The problem I get however is on that last line, whenever I go to try and save the record:
nlapiSubmitRecord(record, true);
I get the following error:
Module does not exist: ../Client/OFI_ActionButtonsClient.js (SYSTEM_LIBS$debugger.sys#475)
Has anyone else come across this? And know what could be causing the issue? Just for reference I am just running this script through the inbuilt script debugger in NetSuite.
Please note as well, I have tried writing this up using SuiteScript 2.0, and my issue then was that only custom fields were being saved, whereas the primary/ inbuilt fields for the quote in NetSuite had no values added at all.
Thank you
Please provide the entire code. Are you using any library scripts.
Seems you're trying to use a relative path to access a dependency library while running on the debugger
../Client/OFI_ActionButtonsClient.js
Use the full path instead
/SuiteScripts/{your path}/Client/OFI_ActionButtonsClient.js
So I managed to fix the issue. The problem was with me trying to set the customform field. So removing this line in my own code helped fix the issue, and I was able to successfully save the record:
record.setFieldValue('customform', '123' );
Initially I thought it was a problem with the save, but it seems like it was actually happening much earlier on, and only just manifested itself at the point of saving. I'm not entirely sure why that was the case, but for anyone else who might be stuck on this I thought it might be useful to know.
Thanks all.

Using GooglePay with Stripe Gateway

I'm having a problem configuring GooglePay using the Stripe gateway because it says the "stripe:publishablekey" is missing after I click the "Continue" button in the GooglePay payment sheet.
In my code, this occurs in the loadPaymentData(paymentDataRequest) line which displays the GooglePay payment sheet and is supposed to return a response(with a payment token) after finishing according to this. But is not happening because of the error I mentioned above.
In my paymentDataRequest object, I already have the "stripe:publishablekey" field and I don't get why it's saying that it's missing.
I've already tried copying the field that is in the Tutorial from Google where the "k" in the stripe:publishablekey is supposed to be capitalised like this "K" but it only gives another error message that says "stripe:publishableKey" is an invalid field.
Sorry for my bad english and also this is my first time asking a question in stackoverflow.
I can't say for sure what the problem that you're facing is, however, I was able to get it to work with the following: https://jsfiddle.net/u3snqdwm/
FYI, I'm using stripe:publishableKey with a capitalized K.
tokenizationSpecification: {
type: 'PAYMENT_GATEWAY',
parameters: {
'gateway': 'stripe',
'stripe:version': '2018-10-31',
'stripe:publishableKey': 'pk_test_MNKMwKAvgdo2yKOhIeCOE6MZ00yS3mWShu'
},
},

INVALID_RECORD_TYPE when voiding CHECK in Netsuite using Suitescript 2.0?

I'm trying to void transactions via script. It's working for all the other transactions except for check record and I can't figure out why. I'm getting the INVALID_RECORD_TYPE error.
Here's a sample code I am using.
var id = transaction.void({
type: 'check',
id: 25
});
Thanks.
Please check Setup > Accounting > Accounting Preferences > General: VOID TRANSACTIONS USING REVERSING JOURNALS.
If the preference is not checked, the Void button does not appear in checks and you get the invalid record type error.
Please check the Field Level help of the preference for details. You will need to toggle the preference (using N/config) before calling transaction.void on types that are not covered by your account setting.
You must Reversing Journal
and then this:
var checkId= transaction.void({
type: transaction.Type.CHECK,
id: 25
});

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');

How can I clear an external ID on a record in NetSuite?

I need to clear/reset the external ID on a record in NetSuite, but nothing I do is working.
Some of the InventoryItem records are incorrectly mapped to records in another system. I have an application that can sync up the two systems, but I need to clear NetSuite's external IDs first.
Responses don't really need to be SOAP-specific. If you know how to do it with some specific NetSuite/SuiteTalk client, that might point me in the right direction.
What I've Tried
First up, I tried using the nullFieldList... but maybe it doesn't work because externalId is an attribute, not an element?
<messages:update>
<messages:record internalId="7777" xsi:type="accounting:InventoryItem">
<core:nullFieldList xsi:type="core:NullField">
<core:name>externalId</core:name>
</core:nullFieldList>
</messages:record>
</messages:update>
The external ID is just a string, so I tried just setting it to blank. Didn't work either.
<messages:update>
<messages:record internalId="7777" xsi:type="accounting:InventoryItem">
<accounting:externalId></accounting:externalId>
</messages:record>
</messages:update>
I even tried setting the external ID to 0, but I get back a "not unique identifier" error
<messages:update>
<messages:record internalId="7777" xsi:type="accounting:InventoryItem">
<accounting:externalId>0</accounting:externalId>
</messages:record>
</messages:update>
Other Info
I'm using NetSuite's SOAP API v.2013_1
When I say "it doesn't work", I mean: after I do the update, I get a success response similar to the following:
<readResponse>
<platformCore:status isSuccess="true" xmlns:platformCore="urn:core_2013_1.platform.webservices.netsuite.com"/>
<record internalId="7777" externalId="42" xsi:type="listAcct:InventoryItem" xmlns:listAcct="urn:accounting_2013_1.lists.webservices.netsuite.com">
<!-- snip -->
</record>
</readResponse>
If you are using scripts in netsuite you can run a scheduled script to clear records in NS by loading each record and setting the externalid to '' using the following simple code:
var rec= nlapiLoadRecord(type,id);
rec.setFieldValue('externalid','');
nlapiSubmitRecord(rec);
This seemed to work for me in my enviornment which was on 2015.2.
Unfortunately my understanding is that once you set an externalid you cannot clear it, you can set it to another value, but not back to null. I have experienced this both using SuiteScript as well as a Boomi process that uses the 2014.1 endpoint. This may have changed in the recent releases, as I have not tried it recently with SuiteScript nor with a newer endpoint.
You can eliminate the externalId on a record once it's been set. Here's an example using the NetSuite gem:
ns_customer = NetSuite::Records::Customer.get external_id: 'ext_id'
ns_customer.external_id = ''
ns_customer.update
Here's the corresponding XML for update:
<env:Body>
<platformMsgs:update>
<platformMsgs:record xsi:type="listRel:Customer" platformMsgs:internalId="199113" platformMsgs:externalId=""/>
</platformMsgs:update>
</env:Body>
I have had to attempt this before as well. I know the pains you describe. I ended up putting a "-" in front of my external ID to unlink it between my systems. You can do this in SOAP or even as a simple one time csv upload. As it was one time, I did csv.

Resources