import odoo import json def create_lab_requests(cr): env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) # Delete unwanted demo sale orders unwanted_orders = env['sale.order'].search([('name', 'in', ['S00001', 'S00002', 'S00003', 'S00004', 'S00005', 'S00006', 'S00007', 'S00008', 'S00009', 'S00010', 'S00011', 'S00012', 'S00013', 'S00014', 'S00015', 'S00016', 'S00017', 'S00018', 'S00019', 'S00020', 'S00021', 'S00022'])]) for order in unwanted_orders: try: order.action_cancel() except Exception: pass try: unwanted_orders.unlink() except Exception: pass # Get patient and doctor patient1 = env.ref('lims_management.demo_patient_1') doctor1 = env.ref('lims_management.demo_doctor_1') patient2 = env.ref('lims_management.demo_patient_2') # Get analysis products hemograma = env.ref('lims_management.analysis_hemograma') perfil_lipidico = env.ref('lims_management.analysis_perfil_lipidico') # Create Lab Request 1 env['sale.order'].create({ 'partner_id': patient1.id, 'doctor_id': doctor1.id, 'is_lab_request': True, 'order_line': [ (0, 0, {'product_id': hemograma.product_variant_id.id, 'product_uom_qty': 1}), (0, 0, {'product_id': perfil_lipidico.product_variant_id.id, 'product_uom_qty': 1}) ] }) # Create Lab Request 2 env['sale.order'].create({ 'partner_id': patient2.id, 'is_lab_request': True, 'order_line': [ (0, 0, {'product_id': hemograma.product_variant_id.id, 'product_uom_qty': 1}) ] }) if __name__ == '__main__': db_name = 'lims_demo' registry = odoo.registry(db_name) with registry.cursor() as cr: create_lab_requests(cr) cr.commit()