Odoo new api : What is the equivalence of _prepare_order_line_move method in the new API? - odoo-12

I'm working in migrating from old API code to the new API code but stuck with the _prepare_order_line_move method.
Here is the old API code :
class purchase_order(osv.osv):
_name = 'purchase.order'
_inherit = 'purchase.order'
def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, context=None):
if context is None:
context={}
res=super(purchase_order,self)._prepare_order_line_move(cr, uid, order, order_line, picking_id, context)
res['qty_uos2'] = order_line.product_qty
res['uos_id2'] = order_line.product_uom.id
res['product_qty'] = order_line.qty_uos2
res['product_uos_qty'] = order_line.qty_uos2
res['product_uom'] = order_line.uos_id2.id
res['product_uos'] = order_line.uos_id2.id
return res
Can you help me? Thank you very much.
PS : Odoo 8.0 to Odoo 12.0

Related

Calling a custom function in Rasa Actions

I am facing a problem in developing a chatbot using rasa .
I am trying to call a custom function in rasa action file. But i am getting an error saying "name 'areThereAnyErrors' is not defined"
here is my action class. I want to call areThereAnyErrors function from run method. Could someone please help how to resolve this?
class ActionDayStatus(Action):
def areThereAnyErrors(procid):
errormessagecursor = connection.cursor()
errormessagecursor.execute(u"select count(*) from MT_PROSS_MEAGE where pro_id = :procid and msg_T = :messageT",{"procid": procid, "messageT": 'E'})
counts = errormessagecursor.fetchone()
errorCount = counts[0]
print("error count is {}".format(errorCount))
if errorCount == 0:
return False
else:
return True
def name(self):
return 'action_day_status'
def run(self, dispatcher, tracker, domain):
import cx_Oracle
import datetime
# Connect as user "hr" with password "welcome" to the "oraclepdb" service running on this computer.
conn_str = dbconnection
connection = cx_Oracle.connect(conn_str)
cursor = connection.cursor()
dateIndicator = tracker.get_slot('requiredDate')
delta = datetime.timedelta(days = 1)
now = datetime.datetime.now()
currentDate = (now - delta).strftime('%Y-%m-%d')
print(currentDate)
cursor = connection.cursor()
cursor.execute(u"select * from M_POCESS_FILE where CREATE_DATE >= TO_DATE(:createDate,'YYYY/MM/DD') fetch first 50 rows only",{"createDate":currentDate})
all_files = cursor.fetchall()
total_number_of_files = len(all_files)
print("total_number_of_files are {}".format(total_number_of_files))
Answer given by one of the intellectuals :
https://realpython.com/instance-class-and-static-methods-demystified/ Decide whether you want a static method or class method or instance method and call it appropriately . Also when you are using connection within the function it should be a member variable or passed to the method You dont have self as a parameter so you may be intending it as a static method - but you dont have it created as such

How to set defaut value for a many2one field in Odoo 9.0c?

I have customized a module that include a many2one field. Now, I would like to set the default value for that field with the codition is: [[u'bom_ids', u'!=', False]]. i have tried below code but it did not work probebly
width_id = field.Many2one('sale.order.line.width', default ='_get_width_default')
def _get_width_default(self, cr, uid, context=None):
res = self.pool.get('product.template').search(cr, uid, [(u'bom_ids', u'!=', False)], context=context)
return res and res[0] or False
default = {
'width_id' : _get_width_default,
}
Could you guy please help me to point what is the problem and how to sovle the problem and finnally get my purpose. Thank for watching
import logging
_logger = logging.getLogger(__name__)
def _get_width_default(self, cr, uid, context=None):
#REPLACE DOMAIN WITH SOMETHING RELEVANT
domain = []
res = self.pool.get('sale.order.line.width').search(cr, uid, domain, context=context)
_logger.info("PREPARING DEFAULT VALUE")
_logger.info(res)
return res[0] or False
width_id = fields.many2one('sale.order.line.width')
_defaults = {
'width_id' : _get_width_default,
}
What do you see as far as logging is concerned? Try the above code (v7 style).
Odoo9 Style (NEW API)
import logging
_logger = logging.getLogger(__name__)
def _get_width_default(self):
#REPLACE DOMAIN WITH SOMETHING RELEVANT
domain = []
res = self.env['sale.order.line.width'].search(domain)
_logger.info("PREPARING DEFAULT VALUE")
_logger.info(res)
return res[0].id or False
width_id = fields.many2one('sale.order.line.width',default=_get_width_default)

How to set TotalAmount for SalesReciept

I'm using QBO Rest API V3 SDK and trying to create a deposit onto an account. It seems there isn't a deposit transaction anymore, so am trying to use a SalesReciept to do so.
The call is succeeding and the transaction is created however the SalesReciept is returned with a TotalAmount of zero. When I look at the QBO application it shows a 0 Deposit amount as well.
I noticed there was a UnitPrice on the API, but was missing from the SDK, so I hand crafted a web request and it still came back with a 0.
If there is another approach I should take let me know.
var deposit = new SalesReceipt()
{
DepositToAccountRef = new ReferenceType()
{
Value = "1",
name = "MyAccount"
},
TxnDate = transaction.TransactionDate,
TxnDateSpecified = true,
TotalAmt = transaction.Amount,
TotalAmtSpecified = true,
Line = new[]
{
new Line()
{
Amount = transaction.Amount,
AmountSpecified = true,
Description = transaction.DisplayBody,
DetailType = LineDetailTypeEnum.SalesItemLineDetail,
DetailTypeSpecified = true,
AnyIntuitObject = new SalesItemLineDetail()
{
ItemRef = new ReferenceType(){
Value = qboIntegration.IncomeAccountId,
name = GetIncomeAccountName(),
},
Qty = 1,
QtySpecified = true,
TaxInclusiveAmt = transaction.Amount,
TaxInclusiveAmtSpecified = true,
ServiceDate = transaction.TransactionDate,
ServiceDateSpecified = true,
},
}
},
};
I've not tried this using .net sdk. You can try the following ( Ref - SO Thread).
AnyIntuitObject = new SalesItemLineDetail()
{
ItemElementName = ItemChoiceType.UnitPrice,
AnyIntuitObject = amount,
...
},
DetailType = LineDetailTypeEnum.SalesItemLineDetail
To get the correct object structure you can create a salesReceipt from QBO UI(with desired attribute value) and retrieve the same using getById endpoint.
To do the above, you can use the ApiExplorer tool as well.
https://developer.intuit.com/apiexplorer?apiname=V3QBO
Thanks
After contacting quickbooks. It is not possible with the current iteration (V3) of the api. They are considering adding this in the next version.

IPP v3 Invoice QueryService not working with Skip/Take when using non-default fields

I'm trying to query invoices using the .NET IPP DevKit v3.
Following all the directions found on the documentation site, I can query invoices and add skip/take/order by/where/etc to the query when using ONLY default fields. But, as soon as I add non-default fields, skip/take/order by/where/etc does NOT seem to work.
Here's the error:
System.ArgumentException was unhandled
HResult=-2147024809
Message=Expression of type 'System.Collections.Generic.IEnumerable`1[<>f__AnonymousType0`3[Intuit.Ipp.Data.Invoice,Intuit.Ipp.Data.Line[],Intuit.Ipp.Data.LinkedTxn[]]]' cannot be used for parameter of type 'System.Linq.IQueryable`1[<>f__AnonymousType0`3[Intuit.Ipp.Data.Invoice,Intuit.Ipp.Data.Line[],Intuit.Ipp.Data.LinkedTxn[]]]' of method 'System.Linq.IQueryable`1[<>f__AnonymousType0`3[Intuit.Ipp.Data.Invoice,Intuit.Ipp.Data.Line[],Intuit.Ipp.Data.LinkedTxn[]]] Skip[<>f__AnonymousType0`3](System.Linq.IQueryable`1[<>f__AnonymousType0`3[Intuit.Ipp.Data.Invoice,Intuit.Ipp.Data.Line[],Intuit.Ipp.Data.LinkedTxn[]]], Int32)'
Source=System.Core
What am I missing here?
Code:
string AppToken = "your AppToken goes here";
string AppConsumerKey = "your AppConsumerKey goes here";
string AppConsumerKeySecret = "your AppConsumerKeySecret goes here";
string AccessToken = "your AccessToken goes here";
string AccessTokenSecret = "your AccessTokenSecret goes here";
string RealmCompanyId = "your RealmId goes here";
OAuthRequestValidator oauthValidator = new OAuthRequestValidator(AccessToken, AccessTokenSecret, AppConsumerKey, AppConsumerKeySecret);
ServiceContext context = new ServiceContext(AppToken, RealmCompanyId, IntuitServicesType.QBD, oauthValidator);
QueryService<Intuit.Ipp.Data.Invoice> qs = new QueryService<Intuit.Ipp.Data.Invoice>(context);
// This works...
var defaultQuery = qs.Select(c => c).Skip(0).Take(10).OrderBy(c => c.Id);
var defaultList = defaultQuery.ToList();
// This works...
var nonDefaultQuery = qs.Select(c => new { c, c.Line, c.LinkedTxn });
var nonDefaultList = nonDefaultQuery.ToList();
// This does NOT work!!
var nonDefaultQueryWithSkip = qs.Select(c => new { c, c.Line, c.LinkedTxn }).Skip(0).Take(10);
var nonDefaultListWithSkip = nonDefaultQueryWithSkip.ToList();
I tried on the API explorer-
Select *,Line.*, LinkedTxn.* FROM Invoice startPosition 1 maxResults 10 (which is your last query) and it works fine but not from .net sdk. I will double check this on the .net SDK and get back to you. Can you verify that you get the correct results on API explorer from this query?
This now works in the latest version (IppDotNetSdkForQuickBooksApiV3.2.0.0)
Here's an example:
QueryService<Intuit.Ipp.Data.Invoice> qs = new QueryService<Intuit.Ipp.Data.Invoice>(context);
string query = string.Format("SELECT *, Line.* FROM Invoice ORDERBY Id STARTPOSITION {0} MAXRESULTS {1}", startPos, pageSize);
var recs = qs.ExecuteIdsQuery(query);
foreach (Intuit.Ipp.Data.Invoice rec in recs)
{
// do stuff...
}
.

How to read the unit price of an Item with IPP DevKit

I've seen elsewhere how to set the UnitPrice on an Item, using the wiley and elusive Item1 field as Intuit.Ipp.Data.Qbd.Money. But how do I READ the unit price from the Item1 field? I can't cast it. The new operator doesn't work ("new ...Money(myItem.Item1)"). So how do I get the price?
I realize the DevKit will probably never be changed so this makes sense. But can we at least get some doc explaining all those strange "xxxItemxxx" fields?
ServiceContext context = new ServiceContext(oauthValidator, realmId, intuitServiceType);
DataServices commonService = new DataServices(context);
Intuit.Ipp.Data.Qbd.Item qbdItem = new Intuit.Ipp.Data.Qbd.Item();
Intuit.Ipp.Data.Qbd.Money unitPrice = new Intuit.Ipp.Data.Qbd.Money();
unitPrice.Amount = 22;
unitPrice.AmountSpecified = true;
qbdItem.Item1 = unitPrice;
IEnumerable<Intuit.Ipp.Data.Qbd.Item> qbdItemsResult = commonService.FindAll(qbdItem, 1, 10) as IEnumerable<Intuit.Ipp.Data.Qbd.Item>;
foreach (var itemResult in qbdItemsResult)
{
Intuit.Ipp.Data.Qbd.Money test1UnitPrice = itemResult.Item1 as Intuit.Ipp.Data.Qbd.Money;
}
You can use the above code for .Net.
Response XML of Item entity suggests that 'UntiPrice' is a top level tag.
I tried this usecase using java. PFB code.
QBItemService itemService = QBServiceFactory.getService(context,QBItemService.class);
items = itemService.findAll(context,1, 100);
for (QBItem item : items) {
System.out.println("Name - " + item.getName() + " UnitPrice - " + item.getUnitPrice().getAmount());
Can you please try the same in .Net and let me know if it works in the same way.
Intuit.Ipp.Data.Qbd.Money [ getAmount() ]
Thanks