未加星标

Upgrading to Odoo 12

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二03 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

Odoo 12.0 is out since october. I am currently investigating the differences with previous versions to update the instance of the association Les Compagnons du CEP . A lot of changes have been made in a few years but the workflow stays about the same. For example, merging purchase order is impossible in this version. This article describes my workflow, the backup policy, how a module was used and fixed to restore this feature. Finally, the changes in my custom product import function are presented.

Production and debug setup

Agayon.be instance of Odoo runs inside a Docker container on a small VPS. Postgresql is installed as a core package. This setup is great in production but it is difficult to debug some python code with this configuration. The first step is to run Odoo with an IDE (I personally use the excellent Pycharm ).

Running and debugging Odoo

The first step is the creation of the virtualenv. Once the Postgresql instance is ready , you can build the environment.

git clone https://www.github.com/odoo/odoo --depth 1 --branch 12.0 $ virtualenv myenv $ source myenv/bin/activate (myenv)$ pip install -r odoo/requirements.txt (myenv)$ mkdir custom-addons (myenv)$ chown odoo: odoo11-custom-addons

Edit odoo.conf and then run odoo:

odoo/odoo-bin -c odoo.conf Merge purchase order

Unfortunately, a major feature has disappeared in version 12.0: automatic merge of purchase order. I don't know why since it seems unrealistic to send each quotation separately to your vendor. Fortunately a free module can be used to perform the merge but it has a critical bug. Some quotation lines are merged even if they concerns different products .

Fix

After forking it, I decided to start by refactoring it. The module is quite small but a lot of code is duplicated. As I try to avoid spaghetti code , it needed to be refactored .I think the new code may be improved but no line is duplicated. Finally, the bug has been fixed .

Backup management

Since a few version, the filestore is mandatory in Odoo. If it is incoherent with the database, some really annoying errors are raised and the solution is quite tedious. My backup procedure has been updated to avoid losing any data. It is based on the article from zeroheure . The backups are saved with the auto_backup module. Restoring the data is not possible with the web interface because the process reaches the memory limit but it can be performed with the following shell script.

#!/bin/bash BACKUPLOCATION="/path/to/backup.zip" DBNAME="db_name" FILESTORE_DIR="/path/to/filestore" if [ -z "$FILESTORE_DIR" ] || [ -z "$DBNAME" ] || [ -z "$BACKUPLOCATION" ] then echo "verify your variables" else cd $BACKUPLOCATION rm filestore unzip -q $DBNAME.zip cp -r filestore $DBNAME sudo rm -rf $FILESTORE_DIR/$DBNAME sudo mv $DBNAME $FILESTORE_DIR sudo chown -R odoo:odoo $FILESTORE_DIR/$DBNAME dropdb -U odoo $DBNAME createdb -U odoo $DBNAME psql $DBNAME --quiet < dump.sql fi Wine import with Django website

Version 12.0 needs some minor changes in the code displayed in theprevious article. These modifications includes:

removing state property in the product template. Adding the invoice_policy and purchase_method in the product template. Add a reference to the standard price in the product_supplierinfo dictionary. This value is used in the orders when purchasing wines to suppliers. def research(default_code, supplier_code, wine_name): # 1) search if default code is used?) # 2) search if suppliers is in the database # 3) search if the name is already used # Retrieve the dataframes. This example comes from a jupyter nootebook. # df_product and df_sellers are already defined. # In a real case, we should use class variables. n_code, df_code = search_df(df=df_product, col_name='default_code', search_item=default_code, search_int=False) n_supplier, df_suppliers = search_df(df=df_suppliers, col_name='function', search_item=supplier_code, search_int=False) n_name, df_name = search_df(df=df_product, col_name='name', search_item=wine_name, search_int=False) try: # ids_product = list(df_code['id']) ids_product = df_code['id'].tolist() except AttributeError: ids_product = [] if n_code == 0 and n_name == 0 and n_supplier != 0: return 'success', ids_product, n_supplier, n_name if n_code != 0 and n_name != 0: # Another product uses the same name with another code return 'e_code_used_same_name', ids_product, n_supplier, n_name if n_code != 0: # the code is already used return 'e_code_used', ids_product, n_supplier, n_name if n_supplier == 0: # Cannot find the supplier return 'e_missing_seller', ids_product, n_supplier, n_name if n_name != 0: # A product with the same name and another code exists. return 'e_code_used_different_name', ids_product, n_supplier, n_name def import2odoo(): route_warehouse0_mto = 1 route_warehouse0_manufacture = 5 [...] # iterate over all rows, read the cells and assign the wine parameters to variables # each row correspond to one wine for row in rows: seller_name = row[0] default_code = row[1] name = row[2] do_import = row[2] comment = row[3] name = row[4] default_code = row[5] standard_price = row[6] list_price = row[7] seller_code = row[8] res_search, ids_product, n_supplier, n_name = research(default_code, seller_code, name) if res_search == 'success' and do_import == "1": product_template = { 'name': name, 'active': True, 'standard_price': standard_price, 'list_price': list_price, 'description': comment , 'default_code': default_code, 'purchase_ok': 1, 'sale_ok': 1, 'uom_id': 1, 'uom_po_id': 1, 'type': 'product', 'cost_method': 'standard', 'invoice_policy' : 'order' , # ordered quantities 'purchase_method' : 'receive', # control received quantities (or ordered ones, test to delivery) 'route_ids': [(6, 0, [route_warehouse0_mto, route_warehouse0_manufacture])] } # For each wine, a template must be created template_id = sock.execute(dbname, uid, pwd, 'product.template', 'create', product_template) # Create the supplier information for the wine product_supplierinfo = { 'name': name, 'product_code': row[1], # code for supplier 'product_name': row[15], # name for supplier 'min_qty': 1, 'delay': 300, 'product_tmpl_id': template_id, 'price' : standard_price, } # Create the supplier information for the wine product_supplierinfo_id = sock.execute(dbname, uid, pwd, 'product.supplierinfo', 'create', product_supplierinfo) logging.info("Wine {} : {} has been added".format(default_code, name)) [...] # Here we take into account the exceptions and several cases: the wine is already present, the seller is missing etc. Conclusions

After using Odoo in production for 4 years, I still love it. My users are happy to use it daily and the improvements over the year are impressive. Like any other alive project, some changes may break the workflow but Odoo and it's community make it relatively simple to adapt with plugins. Odoo 12 is strong and I look forward to use it for the next 3 years :-).

Links Odoo Backup management zeroheure backup quick help

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

代码区博客精选文章
分页:12
转载请注明
本文标题:Upgrading to Odoo 12
本站链接:https://www.codesec.net/view/611143.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(80)