Last active
August 6, 2020 22:48
-
-
Save komuw/59b871a14cfc55186f5f to your computer and use it in GitHub Desktop.
Creating and updating a sale.order in openERP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################## | |
#Creating a sale order including the products.# | |
import oerplib | |
oerp = oerplib.OERP('localhost', protocol='xmlrpc', port=8069) | |
user = oerp.login('user', 'passwd', 'db_name') | |
#create a dictionary with fields and their values. the dict ought to have at a minimum all the fields that are marked required=True for that model | |
sale_order_dict = { | |
'picking_policy': 'direct', | |
'currency_id': 98, | |
'shop_id': 1, | |
'date_order': '2014-05-07', #you can leave out this field, openERP will fill it appropriately | |
'partner_id': 6, | |
'pricelist_id': 1, | |
'partner_invoice_id': 6, | |
'name': 'komu_created', #this can also be left out, openERP will use its conventional naming | |
'partner_shipping_id': 6, | |
'invoice_quantity': 'order' | |
} #replace shop_id, partner_ids etc with appropriate ones if need be. | |
#note that the relation; partner_id == partner_invoice_id == partner_shipping_id has to be satisfied | |
#create the sale order | |
sale_order = oerp.create('sale.order', sale_order_dict) #that should return the sales order's id | |
#we've created the sale order but it doesn't have any products in it. now lets populate it with products; | |
#create the sale.order.order_line (with products) | |
##create a dictionary with fields and their values. the dict ought to have at a minimum all the fields that are marked required=True for the sale.order.line model | |
sale_order_line_dict = { | |
'order_id': sale_order, | |
'name': 'Laptop E5023', | |
'product_id': 26, | |
'price_unit': 2950.0, | |
'type': 'make_to_stock', | |
'product_uom_qty': 1.0, | |
'product_uom': 1, | |
'state': 'confirmed' | |
} | |
#create the sale.order.line | |
sale_order_line = oerp.create('sale.order.line', sale_order_line_dict) #returns sale.order.line id | |
#Now update our sale.order so that it contains the product/s in the sale.order.line we just created | |
order_update = oerp.get('sale.order').browse(sale_order) | |
order_update.order_line = [sale_order_line] | |
oerp.write_record(order_update) | |
#if you open your browser you should see the new order. | |
####################### | |
##extra stuff; | |
#by default if you do not specify a state field in the sale_order_dict dictionary, the sale.order will be created with a state='draft'. | |
#thus the sale.order will not show up in the sale.orders but rather in the quotations section. | |
# the state field can take different values: | |
('draft', 'Draft Quotation'), | |
('sent', 'Quotation Sent'), | |
('cancel', 'Cancelled'), | |
('waiting_date', 'Waiting Schedule'), | |
('progress', 'Sales Order'), | |
('manual', 'Sale to Invoice'), | |
('invoice_except', 'Invoice Exception'), | |
('done', 'Done') | |
#if u want the sale.order to show up in the sale.order section, you can create/update it with another state for example; | |
order_update = oerp.get('sale.order').browse(sale_order) | |
order_update.state = 'progress' | |
oerp.write_record(order_update) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment