تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
6208 أدوات العرض

Hey, I have this code. So I don't understand to change this code to ORM. So give me some advice! Thanks so much.

@api.model
def compute_pattern(self, pattern, field):
sql = """
SELECT %s
FROM product_material
WHERE %s LIKE '%s%%'
ORDER BY %s DESC
LIMIT 1
""" % (field, field, pattern, field)
self._cr.execute(sql)
sql_result = self._cr.fetchone()
sql_result = sql_result and sql_result[0] or False
if not sql_result:
return pattern + '001'
digit = sql_result.split(pattern)[1]
digit = str(int(digit) + 1)
while len(digit) < 3:
digit = '0' + digit
return pattern + digit
الصورة الرمزية
إهمال

why change to orm function?

الكاتب

So, I just need to change thís code to ORM from my Team Leader

Learn some ERP customization stuff: https://www.scoop.it/t/learn-openerp

Hope this will helps you and others...

الكاتب

Thanks, Sehrish :) !

أفضل إجابة

here is the start

pool_obj = self.pool['product_material'];
pool_results = pool_obj.search([(field, 'like', pattern }} ... 

read the rest here: https://www.odoo.com/documentation/12.0/reference/orm.html

don't expect others to do your job.

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Thanks, I just need some advice! I'm newbie.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يونيو 24
1896
3
سبتمبر 22
16728
1
يونيو 19
2560
1
يناير 19
4526
4
فبراير 24
2514