The Problem
Company growth caused Quickbooks Desktop to be inadequate at managing the company inventory
Skills Required
Python
Odoo is an open source ERP built using Python and the framework and all modules are written in Python
HTML/CSS/JavaScript/XML
Views are handled by Odoo and converted to HTML from XML with functionality from CSS and JavaScript
Linux Command Line
This Odoo instance is run on a Ubuntu Server
Website Security
NGINX and an IP management script to secure the server
The Project
Due to company growth QuickBooks Desktop became insufficient to track inventory location and manufacturing. I was tasked with sourcing an inexpensive software solution and selected Odoo after looking into all appropriate options. I chose Odoo because it was open source and modular with a powerful community version capable of all required operations. After setting up an instance and importing all inventory data, I proposed and implemented a module to track projects requiring large regular product shipments. I also developed a simple connector application to import sales orders from QuickBooks to preserve the established company workflow during the software transition. Further company growth created a need for access to the Odoo instance from outside the local network environment. I ported all custom modules from Windows to Linux and created a new Odoo instance on a Ubuntu server using the cloud service DigitalOcean. All company data was moved to the new instance and I configured all proxy and security settings to protect a web facing database using NGINX. I am currently overseeing the migration of an additional company’s database onto the existing Odoo instance.
Project Manager Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | # -*- coding: utf-8 -*- from odoo import models, fields, api from datetime import datetime class primary_sale_order(models.Model): _name = 'sale.pso' name = fields.Char( 'Project Name' , required = True ) origin_po = fields.Char( 'Original PO Number' ) origin_so = fields.Char( 'Original SO Number' , required = True ) customer_id = fields.Many2one( 'res.partner' , string = 'Customer' , required = True ) sale_order = fields.One2many( 'sale.order' , 'primary_sale_order' , string = 'Sub Sale Order' ) sale_line = fields.One2many( 'sale.pso.line' , 'primary_sale_order' , string = 'Sale Line' ) state = fields.Char( 'Status' , readonly = True , default = 'draft' ) origin_so_date = fields.Datetime( 'Original Sale Order Date' ) @api .multi def action_sale_order_calendar( self ): assert len ( self ) = = 1 , 'This option should only be used for a single id at a time.' #template = self.env.ref('account.email_template_edi_invoice', False) id = self . id return { 'name' : 'sale order calendar action wizard' , 'res_model' : 'sale.order' , 'res_id' : id , 'type' : 'ir.actions.act_window' , #'context': {'primary_sale_order', '=', 'self'}, 'view_mode' : 'calendar,tree,form' , 'view_type' : 'form' , 'view_id' : self .env.ref( 'sale.view_sale_order_calendar' ), 'target' : 'new' , #'target': 'current', } @api .model def create( self , vals): result = super (primary_sale_order, self ).create(vals) result.state = 'saved' return result @api .multi def action_sale_order_create( self ): data = self ._prepare_sale_order() order = self .env[ 'sale.order' ].create(data) for line in self .sale_line: line.sale_order_line_create(order. id ) action = self .env.ref( 'sale.action_orders' ).read()[ 0 ] action[ 'views' ] = [( self .env.ref( 'sale.view_order_form' ). id , 'form' )] action[ 'res_id' ] = order. id return action @api .multi def _prepare_sale_order( self ): self .ensure_one() res = { 'origin_so' : self .origin_so, 'origin' : self .origin_po, 'partner_id' : self .customer_id. id , 'primary_sale_order' : self . id , } return res def get_qty_ordered( self , product_id): for line in self .sale_line: if product_id = = line.product_id: return line.qty return None def get_qty_backordered( self , product_id): for line in self .sale_line: if product_id = = line.product_id: return line.qty - line.qty_delivered return None class sale_order(models.Model): _inherit = 'sale.order' primary_sale_order = fields.Many2one( 'sale.pso' , string = 'Primary Sale Order' ) origin_so = fields.Char( 'Main Sale Order Number' ) @api .model def _default_products( self ): primary_sale_order = self .env.context.get( 'primary_sale_order' ) if primary_sale_order: lines = {} for line in primary_sale_order.sale_line: lines.append( self .env.sudo().create({ 'product_id' : line.product_id. id , 'order_id' : id })) return lines return False def get_qty_ordered( self , product_id): for line in self .order_line: if line.product_id = = product_id: return line.product_uom_qty return None order_line = fields.One2many( 'sale.order.line' , 'order_id' , string = 'Order Lines' , states = { 'cancel' : [( 'readonly' , True )], 'done' : [( 'readonly' , True )]}, copy = True , auto_join = True , default = _default_products) class sale_order_line(models.Model): _inherit = 'sale.order.line' commitment_line = fields.Many2one( 'sale.pso.line' , string = 'Primary Sale Line' ) class commitment_line(models.Model): _name = 'sale.pso.line' @api .depends( 'sale_line' ) def _get_qty_delivered( self ): for sline in self : res = 0 for line in sline.sale_line: res + = line.qty_delivered sline.qty_delivered = res @api .depends( 'product_id' ) def _get_qty_available( self ): for sline in self : sline.qty_available = sline.product_id.qty_creatable @api .depends( 'sale_line' ) def _get_forcast( self ): now = datetime.now() for sline in self : res = 0 for line in sline.sale_line: for pick in line.order_id.picking_ids: picktime = datetime.strptime(pick.scheduled_date, '%Y-%m-%d %H:%M:%S' ) if pick.state = = 'done' and (picktime.year - now.year) * 12 + picktime.month - now.month < 1 : res + = line.qty_delivered sline.qty_forcast = res @api .depends( 'product_id.bom_ids' ) def _get_bom_lines( self ): for rec in self : lines = self .env[ 'mrp.bom.line' ].search([( 'bom_id.product_id' , '=' , rec.product_id. id )]) rec.bom_line_ids = lines @api .depends( 'product_id.qty_available' ) def _get_qty_onhand( self ): for line in self : line.qty_onhand = line.product_id.qty_available qty_onhand = fields. Float ( 'Quantity On Hand' , readonly = True , compute = '_get_qty_onhand' ) primary_sale_order = fields.Many2one( 'sale.pso' , string = 'Primary Sale Order' , required = True , ondelete = 'cascade' , index = True , copy = False ) product_id = fields.Many2one( 'product.product' , string = 'Product' , required = True ) qty = fields. Float ( 'Quantity Ordered' , required = True ) qty_delivered = fields. Float ( 'Quantity Delivered' , readonly = True , compute = '_get_qty_delivered' ) sale_line = fields.One2many( 'sale.order.line' , 'commitment_line' , string = 'Sale Order Line' ) qty_available = fields. Float ( 'Quantity Available' , readonly = True , compute = '_get_qty_available' ) qty_forcast = fields. Float ( 'Forcasted Stock' , readonly = True , compute = '_get_forcast' ) bom_line_ids = fields.One2many( 'mrp.bom.line' , 'commitment_line_id' , string = 'Line Ids' , compute = '_get_bom_lines' ) @api .multi def _prepare_sale_line( self ): self .ensure_one() res = { 'name' : self .product_id.name, 'product_id' : self .product_id. id , 'price_unit' : 0 , 'product_uom_qty' : 0 , 'commitment_line' : self . id , } return res @api .multi def sale_order_line_create( self , order_id): order_lines = self .env[ 'sale.order.line' ] for line in self : vals = line._prepare_sale_line() vals.update({ 'order_id' : order_id}) order_lines | = self .env[ 'sale.order.line' ].create(vals) return order_lines class stock_picking(models.Model): _inherit = 'stock.picking' backorder_ids = fields.One2many(comodel_name = 'stock.picking' , inverse_name = 'backorder_id' , copy = False , string = 'Backorders' , readonly = True ) tracking_number = fields.Char( 'Tracking Number' ) shipment_carrier = fields.Many2one( 'stock.picking.carrier' , 'Carrier' ) tracking_url = fields.Char( 'Tracking Url' , compute = '_get_tracking_url' , readonly = True ) @api .depends( 'shipment_carrier.tracking_url' , 'tracking_number' ) def _get_tracking_url( self ): for picking in self : picking.tracking_url = (picking.shipment_carrier.tracking_url or ' ') + ' ' + (picking.tracking_number or ' ') def get_qty_backordered( self , product_id): for line in self .sale_id.order_line: if line.product_id = = product_id: for pline in self .move_line_ids: if pline.product_id = = product_id: return line.product_uom_qty - pline.qty_done return None class product(models.Model): _inherit = 'product.product' @api .multi @api .depends( 'stock_move_ids.product_qty' , 'stock_move_ids.state' ) def _compute_creatable( self ): for product in self : if product.bom_count > 0 : qty_list = [] creatable = 0 for bom in product.bom_ids: for line in bom.bom_line_ids: qty_list.append(bom.product_qty / line.product_qty * line.product_id.qty_available) if product.qty_available + min (qty_list) > creatable: creatable = product.qty_available + min (qty_list) qty_list = [] product.qty_creatable = creatable """product.incoming_qty = res[product.id]['incoming_qty'] product.outgoing_qty = res[product.id]['outgoing_qty'] product.virtual_available = res[product.id]['virtual_available'] + min(qty_list)""" else : product.qty_creatable = product.qty_available """product.incoming_qty = res[product.id]['incoming_qty'] product.outgoing_qty = res[product.id]['outgoing_qty'] product.virtual_available = res[product.id]['virtual_available']""" qty_creatable = fields. Float ( 'Quantity Available' , readonly = True , compute = '_compute_creatable' ) image_medium = fields.Binary( "Medium-sized image" , compute = '_compute_images' , inverse = '_set_image_medium' , help = "") @api .model def create( self , vals): if not 'barcode' in vals: vals[ 'barcode' ] = self .env[ 'ir.sequence' ].next_by_code( 'product.product.barcode_sequence' ) return super (product, self ).create(vals) class product_template(models.Model): _inherit = 'product.template' """@api.multi @api.depends('product_variant_ids.qty_creatable') def _compute_creatable(self): for product in self: for key, value in self[product.id].items(): if key in product._fields: product[key] = value""" @api .multi @api .depends( 'product_variant_ids.qty_creatable' ) def _compute_creatable( self ): for template in self : qty_creatable = sum ( [p.qty_creatable for p in template.product_variant_ids]) template.qty_creatable = qty_creatable qty_creatable = fields. Float ( 'Quantity Available' , readonly = True , compute = '_compute_creatable' ) image_medium = fields.Binary( "Medium-sized image" , attachment = True , help = "") class bom_lines(models.Model): _inherit = 'mrp.bom.line' @api .depends( 'product_id.qty_creatable' ) def _get_qty_creatable( self ): for line in self : line.qty_creatable = line.product_id.qty_creatable commitment_line_id = fields.Many2one( 'sale.pso.line' , string = 'Commitment Line' ) qty_creatable = fields. Float ( 'Quantity Available' , readonly = True , compute = '_get_qty_creatable' ) class shipping_carrier(models.Model): _name = 'stock.picking.carrier' name = fields.Char( 'Name' ) tracking_url = fields.Char( 'Tracking Url' ) picking_ids = fields.One2many( 'stock.picking' , 'shipment_carrier' , string = 'Shipments' , readonly = True ) |
Project Manager Custom Delivery Form
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | <? xml version = "1.0" encoding = "utf-8" ?> < odoo > < data > < template id = "custom_delivery_report" > &l t ;t t-call = "web.html_container" > &l t ;t t-call = "web.external_layout" > &l t ;t t-set = "o" t-value = "o.with_context({'lang':o.partner_id.lang})" /> &l t ;t t-if = "o and 'company_id' in o" > &l t ;t t-set = "company" t-value = "o.company_id" >&l t ;/t> &l t ;/t> &l t ;t t-if = "not o or not 'company_id' in o" > &l t ;t t-set = "company" t-value = "res_company" >&l t ;/t> &l t ;/t> < div class = "header" > < div class = "row" > < div class = "col-xs-8 " > < img t-if = "company.logo" t-att-src = "'data:image/png;base64,%s' % to_text(company.logo)" style = "max-height: 85px;" /> </ div > < div class = "col-xs-4" style = "font:15px lucida-console,sans-serif !important;" > < span style = "color:#3498DB; !important;" t-field = "company.partner_id" />< br /> < span t-field = "company.partner_id.street" />< br /> < span t-field = "company.partner_id.street2" />< br /> < span t-field = "company.partner_id.city" />< br /> < span t-field = "company.partner_id.country_id" />< br /> < span t-field = "company.partner_id.vat" />< br /> </ div > </ div > </ div > < div class = "page" > < div class = "oe_structure" /> < div class = "row" > < div class = "col-xs-6" style = "font:15px lucida-console,sans-serif !important;" > < span style = "font-size:15px" >< strong >< u >Customer</ u ></ strong ></ span >< br /> < span t-field = "o.sale_id.partner_id" />< br /> < span t-field = "o.sale_id.partner_id.street" />< br /> < span t-field = "o.sale_id.partner_id.street2" />< br /> < span t-field = "o.sale_id.partner_id.city" />< br /> < span t-field = "o.sale_id.partner_id.country_id" />< br /> < span t-field = "o.sale_id.partner_id.vat" />< br /> </ div > < div class = "col-xs-6 text-right" style = "font:15px lucida-console,sans-serif !important; " > < span style = "font-size:15px" >< strong >< u >Delivery Address</ u ></ strong ></ span > < div t-if = "o.move_lines and o.move_lines[0].partner_id and o.move_lines[0].partner_id.id != o.partner_id.id" > < div > < div t-field = "o.move_lines[0].partner_id" t-field-options = '{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": true}' /> < div t-field = "o.partner_id.vat" /> </ div > </ div > < div t-if = "(o.move_lines and o.move_lines[0].partner_id and o.move_lines[0].partner_id.id == o.partner_id.id) or o.move_lines and not o.move_lines[0].partner_id" > < div t-field = "o.partner_id" t-field-options = '{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": true}' /> < div t-field = "o.partner_id.vat" /> </ div > </ div > </ div > < div class = "row" style = "font:15px lucida-console,sans-serif" > < h2 >< span >< font >Delivery Number: </ font >< span style = "!important;" t-field = "o.name" /></ span >< br /></ h2 > </ div > < div class = "table" > < table border = "1" style = "border-collapse:collapse;" > < tr > &l t ;t t-if = "o.sale_id" > < td align = "center" width = "100px" >< strong >S.O. Date</ strong ></ td > < td align = "center" width = "100px" >< strong >S.O. No.</ strong ></ td > < td align = "center" width = "100px" >< strong >P.O. No.</ strong ></ td > &l t ;/t> < td align = "center" width = "100px" >< strong >Ship Date</ strong ></ td > &l t ;t t-if = "o.sale_id.primary_sale_order" > < td align = "center" width = "100px" >< strong >Project</ strong ></ td > &l t ;/t> </ tr > < tr > &l t ;t t-if = "o.sale_id" > < td align = "center" t-if = "not o.sale_id.primary_sale_order" t-esc = "time.strftime('%m/%d/%Y',time.strptime(o.sale_id.date_order,'%Y-%m-%d %H:%M:%S'))" > </ td > < td align = "center" t-else = "" t-esc = "time.strftime('%m/%d/%Y',time.strptime(o.sale_id.primary_sale_order.origin_so_date,'%Y-%m-%d %H:%M:%S'))" > </ td > < td align = "center" t-if = "not o.sale_id.primary_sale_order" t-esc = "o.sale_id.name" > </ td > < td align = "center" t-else = "" t-esc = "o.sale_id.origin_so" > </ td > < td align = "center" t-esc = "o.sale_id.origin" > </ td > &l t ;/t> < td align = "center" t-esc = "time.strftime('%m/%d/%Y',time.strptime(o.scheduled_date,'%Y-%m-%d %H:%M:%S'))" > </ td > &l t ;t t-if = "o.sale_id.primary_sale_order" > < td align = "center" t-esc = "o.sale_id.primary_sale_order.name" > </ td > &l t ;/t> </ tr > </ table > </ div > < table class = "table table-condensed mt48" t-if = "o.state!='done'" > < thead > < tr > < th >< strong >Product</ strong ></ th > < th >< strong >Quantity</ strong ></ th > &l t ;t t-if = "o.sale_id.primary_sale_order" > < th >< strong >Qty Ordered</ strong ></ th > < th >< strong >Qty Backordered</ strong ></ th > &l t ;/t> </ tr > </ thead > < tbody > &l t ;t t-set = "lines" t-value = "o.move_lines.filtered(lambda x: x.product_uom_qty)" /> < tr t-foreach = "lines" t-as = "move" > < td >< span t-field = "move.product_id" /></ td > < td > < span t-field = "move.product_uom_qty" /> < span t-field = "move.product_uom" /> </ td > &l t ;t t-if = "o.sale_id.primary_sale_order" > < td >< span t-esc = "o.sale_id.primary_sale_order.get_qty_ordered(move.product_id)" > </ span ></ td > < td >< span t-esc = "o.sale_id.primary_sale_order.get_qty_backordered(move.product_id)" > </ span ></ td > &l t ;/t> </ tr > </ tbody > </ table > < table class = "table table-condensed mt48" t-if = "o.move_line_ids and o.state=='done'" > &l t ;t t-set = "has_serial_number" t-value = "o.move_line_ids.mapped('lot_id')" groups = "stock.group_production_lot" /> < thead > < tr > < th >< strong >Product</ strong ></ th > < th name = "lot_serial" t-if = "has_serial_number" > Lot/Serial Number </ th > &l t ;t t-if = "o.backorder_ids" > < th class = "text-center" >< strong >Qty Ordered</ strong ></ th > < th class = "text-center" >< strong >Quantity Shipped</ strong ></ th > < th class = "text-center" >< strong >Qty Backordered</ strong ></ th > &l t ;/t> &l t ;t t-else = "" > &l t ;t t-if = "o.sale_id" > &l t ;t t-if = "o.sale_id.primary_sale_order" > < th class = "text-center" >< strong >Qty Ordered</ strong ></ th > < th class = "text-center" >< strong >Quantity Shipped</ strong ></ th > < th class = "text-center" >< strong >Qty Backordered</ strong ></ th > &l t ;/t> &l t ;t t-else = "" > < th class = "text-center" >< strong >Quantity</ strong ></ th > &l t ;/t> &l t ;/t> &l t ;t t-else = "" > < th class = "text-center" >< strong >Quantity</ strong ></ th > &l t ;/t> &l t ;/t> </ tr > </ thead > < tbody > < tr t-foreach = "o.move_line_ids" t-as = "move_line" > < td > < span t-field = "move_line.product_id" /> < p t-if = "o.picking_type_code == 'outgoing'" > < span t-field = "move_line.product_id.sudo().description_pickingout" /> </ p > < p t-if = "o.picking_type_code == 'incoming'" > < span t-field = "move_line.product_id.sudo().description_pickingin" /> </ p > </ td > &l t ;t t-if = "o.sale_id.primary_sale_order" > < td class = "text-center" >< span t-esc = "o.sale_id.primary_sale_order.get_qty_ordered(move_line.product_id)" > </ span ></ td > &l t ;/t> &l t ;t t-elif = "o.backorder_ids" > < td class = "text-center" >< span t-esc = "o.sale_id.get_qty_ordered(move_line.product_id)" > </ span ></ td > &l t ;/t> < td class = "text-center" > < span t-field = "move_line.qty_done" /> < span t-field = "move_line.product_uom_id" /> </ td > &l t ;t t-if = "o.sale_id.primary_sale_order" > < td class = "text-center" >< span t-esc = "o.sale_id.primary_sale_order.get_qty_backordered(move_line.product_id)" > </ span ></ td > &l t ;/t> &l t ;t t-elif = "o.backorder_ids" > < td class = "text-center" >< span t-esc = "o.get_qty_backordered(move_line.product_id)" > </ span ></ td > &l t ;/t> </ tr > </ tbody > </ table > </ div > < div class = "footer" > < div class = "text-right" >< span >Signature___________________________________</ span ></ div > < div class = "text-center" style = "border-top: 1px solid black;" > < ul class = "list-inline" > < li >Page:</ li > < li >< span class = "page" /></ li > < li >/</ li > < li >< span class = "topage" /></ li > </ ul > </ div > </ div > &l t ;/t> &l t ;/t> </ template > < template id = "report_deliveryslip" inherit_id = "stock.report_deliveryslip" > < xpath expr = "//t[@t-call='stock.report_delivery_document']" position = 'replace' > &l t ;t t-call = "web.html_container" > &l t ;t t-foreach = "docs" t-as = "o" > &l t ;t t-call = "sales_project_manager.custom_delivery_report" t-lang = "o.partner_id.lang" /> &l t ;/t> &l t ;/t> </ xpath > </ template > </ data > </ odoo > |
Project Manager Views Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | <? xml version = "1.0" encoding = "UTF-8" ?> < odoo > <!--record id="action_sale_order_calendar" model="ir.actions.act_window"> <field name="name">Sale Order Calendar (Wizard)</field> <field name="type">ir.actions.act_window</field> <field name="res_model">sale.order</field> <field name="view_type">form</field> <field name="view_mode">calendar,tree,form</field> <field name="view_id" ref="view_sale_order_calendar"/> <field name="target">new</field> </record--> < record model = "ir.ui.view" id = "project_view_form" > < field name = "name" >sale.pso.form</ field > < field name = "model" >sale.pso</ field > < field name = "arch" type = "xml" > < form string = "Projects" > < header > < field name = "state" invisible = "1" /> < button string = "Create new SO" type = "object" name = "action_sale_order_create" attrs = "{'invisible': [('state', '=', 'draft')]}" class = "oe_highlight" /> </ header > < sheet > < div class = "oe_title" > < h1 > < field name = "name" /> </ h1 > </ div > < group > < field name = "customer_id" /> < field name = "origin_so" /> < field name = "origin_po" /> </ group > < group > < field name = "origin_so_date" /> < button name = "sale_order_calendar_action" string = "Open Sale Order Calendar" type = "action" class = "oe_highlight" /> </ group > < notebook > < page string = "Products" > < field name = "sale_line" mode = "tree" > < form string = "Products" > < div class = "oe_title" > < h1 > < field name = "product_id" /> </ h1 > </ div > < group > < field name = "qty" /> < field name = "qty_delivered" /> < field name = "qty_onhand" /> < field name = "qty_available" /> </ group > < field name = "bom_line_ids" mode = "tree" attrs = "{'invisible': [('bom_line_ids', '=', [])]}" > < tree string = "Components" > < field name = "product_id" /> < field name = "product_qty" /> < field name = "qty_creatable" /> </ tree > </ field > </ form > < tree string = "Products On Display" editable = "bottom" > <!-- decoration-danger="qty-qty_forcast < qty_forcast*2 and not qty_available+qty_delivered >= qty" decoration-success="qty_available+qty_delivered >= qty" --> < field name = "product_id" /> < field name = "qty" /> < field name = "qty_delivered" /> < field name = "qty_available" /> </ tree > </ field > </ page > < page string = "Sale Orders" > < field name = "sale_order" mode = "calendar,tree" > < tree string = "Delivery Orders" > < field name = "date_order" /> < field name = "confirmation_date" widget = "date" /> < field name = "state" > &l t ;t t-if = "sale_order.state == 'Sales Order'" > < attribute name = "string" >Delivered</ attribute > &l t ;/t> </ field > </ tree > <!--calendar date_start="confirmation_date" string="Deliveries"> <field name="name"/> </calendar--> < field name = "inherit_id" ref = "sale.view_order_form_view" /> < field name = "type" >form</ field > </ field > </ page > </ notebook > </ sheet > </ form > </ field > </ record > <!--record id="view_sale_order_calendar" model="ir.ui.view"> <field name="name">sale.order.calendar</field> <field name="model">sale.order</field> <field name="arch" type="xml"> <field name="sale_order" mode="calendar,tree"> <tree string="Delivery Orders"> <field name="date_order"/> <field name="confirmation_date" widget="date"/> <field name="state"> <t t-if="sale_order.state == 'Sales Order'"> <attribute name="string">Delivered</attribute> </t> </field> </tree> </field> </field> </record--> < record model = "ir.actions.act_window" id = "sale_order_calendar_action" > < field name = "name" >Sale Order Calendar</ field > < field name = "res_model" >sale.order</ field > < field name = "view_type" >form</ field > < field name = "view_mode" >calendar,form,tree</ field > < field name = "type" >ir.actions.act_window</ field > < field name = "view_id" ref = "sale.view_sale_order_calendar" /> </ record > < record id = "bom_line_search_view" model = "ir.ui.view" > < field name = "name" >mrp.bom.line.search.view</ field > < field name = "model" >mrp.bom.line</ field > < field name = "arch" type = "xml" > < search string = "Bom Lines" > < group expand = "1" string = "Group by..." > < filter name = "group_by_bom" string = "BOM" domain = "[]" icon = "terp_project" context = "{'group_by': 'bom_id'}" /> </ group > < field name = "product_id" /> </ search > </ field > </ record > < record model = "ir.ui.view" id = "project_view_tree" > < field name = "name" >sale.pso.tree</ field > < field name = "model" >sale.pso</ field > < field name = "arch" type = "xml" > < tree string = "Projects" > < field name = "name" /> < field name = "customer_id" /> </ tree > </ field > </ record > < record model = "ir.ui.view" id = "project_view_search" > < field name = "name" >sale.pso.search</ field > < field name = "model" >sale.pso</ field > < field name = "arch" type = "xml" > < search string = "Projects" > < field name = "name" /> < field name = "customer_id" /> </ search > </ field > </ record > < record model = "ir.actions.act_window" id = "project_action" > < field name = "name" >Projects</ field > < field name = "type" >ir.actions.act_window</ field > < field name = "res_model" >sale.pso</ field > < field name = "view_type" >form</ field > < field name = "view_mode" >tree,form</ field > </ record > < menuitem name = "Projects" id = "project_menu" sequence = "4" parent = "crm.crm_menu_root" groups = "base.group_user" action = "project_action" /> < record model = "ir.ui.view" id = "product_normal_form_view" > < field name = "name" >Quantity available(form)</ field > < field name = "model" >product.product</ field > < field name = "inherit_id" ref = "stock.product_form_view_procurement_button" /> < field name = "arch" type = "xml" > < xpath expr = "//button[@name='%(stock.action_stock_level_forecast_report_product)d']" position = "after" > < button type = "action" name = "%(stock.product_open_quants)d" attrs = "{'invisible':[('type', 'not in', ['product','consu'])]}" class = "oe_stat_button" icon = "fa-building-o" > < div class = "o_form_field o_stat_info" > < field name = "qty_creatable" widget = "statinfo" nolabel = "1" /> < span class = "o_stat_text" >Available</ span > </ div > </ button > </ xpath > </ field > </ record > < record model = "ir.ui.view" id = "view_product_available_tree" > < field name = "name" >Quantity Available(tree)</ field > < field name = "model" >product.product</ field > < field name = "inherit_id" ref = "product.product_product_tree_view" /> < field name = "arch" type = "xml" > < field name = "qty_available" position = "after" > < field name = "qty_creatable" /> </ field > </ field > </ record > < record model = "ir.ui.view" id = "view_product_available_kanban" > < field name = "name" >Quantity Available(kanban)</ field > < field name = "model" >product.product</ field > < field name = "inherit_id" ref = "product.product_kanban_view" /> < field name = "arch" type = "xml" > < ul position = "inside" > < li >On Hand: < field name = "qty_available" /></ li > < li >Available: < field name = "qty_creatable" /> < field name = "uom_id" /></ li > </ ul > </ field > </ record > < record model = "ir.ui.view" id = "view_stock_available_form" > < field name = "name" >Quantity Available (form)</ field > < field name = "model" >product.template</ field > < field name = "inherit_id" ref = "stock.product_template_form_view_procurement_button" /> < field name = "arch" type = "xml" > < xpath expr = "//button[@name='%(stock.action_stock_level_forecast_report_template)d']" position = "after" > < button type = "object" name = "action_open_quants" attrs = "{'invisible':[('type', 'not in', ['product','consu'])]}" class = "oe_stat_button" icon = "fa-building-o" > < div class = "o_form_field o_stat_info" > < field name = "qty_creatable" widget = "statinfo" nolabel = "1" /> < span class = "o_stat_text" >Available</ span > </ div > </ button > <!--product_tmpl_id--> </ xpath > </ field > </ record > < record model = "ir.ui.view" id = "open_parent_product" > < field name = "name" >Parent Product (form)</ field > < field name = "model" >product.product</ field > < field name = "inherit_id" ref = "product.product_normal_form_view" /> < field name = "arch" type = "xml" > < xpath expr = "//field[@name='type']" position = "after" > < field name = "product_tmpl_id" required = "False" attrs = "{'invisible': [('id', '=', False)]}" /> </ xpath > </ field > </ record > < record model = "ir.ui.view" id = "view_stock_available_tree" > < field name = "name" >Quantity Available(tree)</ field > < field name = "model" >product.template</ field > < field name = "inherit_id" ref = "stock.view_stock_product_template_tree" /> < field name = "arch" type = "xml" > < field name = "virtual_available" position = "after" > < field name = "qty_creatable" /> </ field > </ field > </ record > < record model = "ir.ui.view" id = "view_stock_available_kanban" > < field name = "name" >Quantity Available(kanban)</ field > < field name = "model" >product.template</ field > < field name = "inherit_id" ref = "stock.product_template_kanban_stock_view" /> < field name = "arch" type = "xml" > < ul position = "inside" > < li t-if = "record.type.raw_value == 'product'" >Available: < field name = "qty_creatable" /> < field name = "uom_id" /></ li > </ ul > </ field > </ record > < record model = "ir.ui.view" id = "stock_picking_tracking_form" > < field name = "name" >tracking number</ field > < field name = "model" >stock.picking</ field > < field name = "inherit_id" ref = "stock.view_picking_form" /> < field name = "arch" type = "xml" > < xpath expr = "//field[@name='backorder_id']" position = "after" > < field name = "tracking_number" /> < field name = "shipment_carrier" /> < field name = "tracking_url" widget = "url" /> </ xpath > <!--<xpath expr="//button[@name='567']" position="after"> <button type="object" </xpath>--> </ field > </ record > < data > < template id = "product.report_simple_label" > < xpath expr = "//div[@class='page']" position = "replace" > < div class = "col-xs-4" style = "padding:10;" > < table style = "border-spacing:0;margin-bottom:0;height:2.6in;width:4.5in;" class = "table" align = "CENTER" > < thead > < tr style = "width: 4.5in;" > < td style = "border: 2px solid black;width: 2.63in;" colspan = "2" class = "col-xs-8" > &l t ;t t-if = "product.default_code" > [< strong t-field = "product.default_code" />] &l t ;/t> < strong t-field = "product.name" /> </ td > </ tr > </ thead > < tbody > < tr style = "width: 4.5in;" > < td style = "border: 2px solid black;text-align: center; vertical-align: middle;" class = "col-xs-5" > < img t-if = "product.barcode and len(product.barcode) == 13" t-att-src = "'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('EAN13', product.barcode, 600, 150)" style = "width:100%;height:50%;" /> < img t-elif = "product.barcode and len(product.barcode) == 8" t-att-src = "'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('EAN8', product.barcode, 600, 150)" style = "width:100%;height:50%;" /> < img t-else = "" t-att-src = "'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('Code128', product.barcode, 600, 150)" style = "width:100%;height:50%;" /> < span t-field = "product.barcode" /> </ td > </ tr > </ tbody > </ table > </ div > </ xpath > </ template > < record id = "sequence_id" model = "ir.sequence" > < field name = "name" >barcode</ field > < field name = "code" >product.product.barcode_sequence</ field > < field name = "padding" >11</ field > < field name = "prefix" >2</ field > < field eval = "1" name = "number_increment" /> </ record > </ data > </ odoo > |
Quickbooks Desktop Sale Order Connector for Odoo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | # To change this license header, choose License Headers in Project Properties. # To change this template file, choose Tools | Templates # and open the template in the editor. from xmlrpc import client import win32com.client import datetime import time dbname = 'database_name' username = 'database_username' pwd = 'username_pswd' #Odoo--------------------------------------------------------------------- class SaleOrder(): customer = '' sale_code = '' invoice_address = '' delivery_address = '' sale_lines = [] def __init__( self , customer, sale_code, invoice_address, delivery_address, sale_lines): self .customer = customer self .invoice_address = invoice_address self .delivery_address = delivery_address self .sale_lines = sale_lines self .sale_code = sale_code class SaleLine(): product_name = '' product_code = '' product_qty = 0 def __init__( self , product_name, product_qty, product_code): self .product_name = product_name self .product_qty = product_qty self .product_code = product_code def CreateSaleOrderOdoo(sale_order): sock_common = client.ServerProxy ( 'database_address/xmlrpc/common' ) sock = client.ServerProxy( 'database_address/xmlrpc/object' ) uid = sock_common.login(dbname, username, pwd) #Search Odoo for customer name customer_id = sock.execute_kw(dbname, uid, pwd, 'res.partner' , 'search' , [[[ 'name' , '=' , sale_order.customer]]]) #Create sales order for customer if len (customer_id) = = 0 : customer_id = sock.execute_kw(dbname, uid, pwd, 'res.partner' , 'create' , [{ 'name' : sale_order.customer}]) sale_order_id = sock.execute(dbname, uid, pwd, 'sale.order' , 'create' , { 'partner_id' : customer_id, 'pricelist_id' : 1 , 'name' : sale_order.sale_code}) else : sale_order_id = sock.execute(dbname, uid, pwd, 'sale.order' , 'create' , { 'partner_id' : customer_id[ 0 ], 'pricelist_id' : 1 , 'name' : sale_order.sale_code}) #Search for each product and add it to the sales order for var in sale_order.sale_lines: product_id = sock.execute_kw(dbname, uid, pwd, 'product.product' , 'search' , [[[ 'name' , '=' , var.product_name]]]) product_code = sock.execute_kw(dbname, uid, pwd, 'product.product' , 'search' , [[[ 'default_code' , '=' , var.product_code]]]) if len (product_code) ! = 0 : sock.execute(dbname, uid, pwd, 'sale.order.line' , 'create' , { 'order_id' : sale_order_id, 'product_id' : product_code[ 0 ], 'product_uom_qty' : var.product_qty}) elif len (product_id) ! = 0 : sock.execute(dbname, uid, pwd, 'sale.order.line' , 'create' , { 'order_id' : sale_order_id, 'product_id' : product_id[ 0 ], 'product_uom_qty' : var.product_qty}) else : product_id = sock.execute(dbname, uid, pwd, 'product.product' , 'create' , { 'name' : var.product_name, 'default_code' : var.product_code}) sock.execute(dbname, uid, pwd, 'sale.order.line' , 'create' , { 'order_id' : sale_order_id, 'product_id' : product_id, 'product_uom_qty' : var.product_qty}) print ( 'Sale Order Created Successfully...!' ) def CheckForSaleOrderOdoo(sale_order): sock_common = client.ServerProxy ( 'database_address/xmlrpc/common' ) sock = client.ServerProxy( 'database_address/xmlrpc/object' ) uid = sock_common.login(dbname, username, pwd) sale_order_id = sock.execute_kw(dbname, uid, pwd, 'sale.order' , 'search' , [[[ 'name' , '=' , sale_order.RefNumber.getvalue()]]]) if len (sale_order_id) = = 0 : return False else : print ( "Sales Order Already Exists In Odoo, Updating..." ) sale_order = ParseQB(sale_order) odoo_sale_lines = sock.execute_kw(dbname, uid, pwd, 'sale.order.line' , 'search' , [[[ 'order_id' , '=' , sale_order_id[ 0 ]]]]) while len (sale_order.sale_lines) > 0 : updated = False line = sale_order.sale_lines.pop( 0 ) for var in odoo_sale_lines: name = sock.execute_kw(dbname, uid, pwd, 'sale.order.line' , 'read' , [var]) if name[ 0 ][ 'name' ] = = line.product_name: sock.execute_kw(dbname, uid, pwd, 'sale.order.line' , 'write' , [[var], { 'product_uom_qty' : line.product_qty}]) odoo_sale_lines.remove(var) updated = True break if not updated: product_id = sock.execute_kw(dbname, uid, pwd, 'product.product' , 'search' , [[[ 'name' , '=' , line.product_name]]]) product_code = sock.execute_kw(dbname, uid, pwd, 'product.product' , 'search' , [[[ 'default_code' , '=' , line.product_code]]]) if len (product_code) ! = 0 : sock.execute(dbname, uid, pwd, 'sale.order.line' , 'create' , { 'order_id' : sale_order_id[ 0 ], 'product_id' : product_code[ 0 ], 'product_uom_qty' : line.product_qty}) elif len (product_id) ! = 0 : sock.execute(dbname, uid, pwd, 'sale.order.line' , 'create' , { 'order_id' : sale_order_id[ 0 ], 'product_id' : product_id[ 0 ], 'product_uom_qty' : line.product_qty}) else : product_id = sock.execute(dbname, uid, pwd, 'product.product' , 'create' , { 'name' : var.product_name, 'default_code' : var.product_code}) sock.execute(dbname, uid, pwd, 'sale.order.line' , 'create' , { 'order_id' : sale_order_id[ 0 ], 'product_id' : product_id, 'product_uom_qty' : line.product_qty}) if len (odoo_sale_lines) > 0 : for var in odoo_sale_lines: sock.execute_kw(dbname, uid, pwd, 'sale.order.line' , 'unlink' , [var]) return True #End of Odoo-------------------------------------------------------------------- #Quickbooks--------------------------------------------------------------------- def CheckForSO(oldDateTime): # Open a QB Session sessionManager = win32com.client.Dispatch( "QBFC10.QBSessionManager" ) sessionManager.OpenConnection(' ', ' Odoo Connector') sessionManager.BeginSession("", 2 ) # Send query and receive response query = sessionManager.CreateMsgSetRequest( "US" , 6 , 0 ) messageQuery = query.AppendSalesOrderQueryRq() messageQuery.IncludeLineItems.SetValue( True ) messageQuery.ORTxnNoAccountQuery.TxnFilterNoAccount.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetValue(oldDateTime, False ) responseMsgSet = sessionManager.DoRequests(query) response = responseMsgSet.ResponseList.GetAt( 0 ) # Disconnect from Quickbooks sessionManager.EndSession() sessionManager.CloseConnection() return response #Parse QB Response Data--------------------------------------------------------- def ParseQB(sale_order): lineList = [] lineListImport = sale_order.ORSalesOrderLineRetList for x in range ( 0 , lineListImport.Count): saleLine = lineListImport.GetAt(x) if (saleLine.SalesOrderLineRet.Desc ! = None and saleLine.SalesOrderLineRet.Quantity ! = None ): lineList.append(SaleLine(saleLine.SalesOrderLineRet.Desc.GetValue(), saleLine.SalesOrderLineRet.Quantity.GetValue(), saleLine.SalesOrderLineRet.ItemRef.FullName.GetValue())) print (sale_order.TimeModified.GetValue()) return SaleOrder(sale_order.CustomerRef.FullName.GetValue(), sale_order.RefNumber.GetValue(), ' ', ' ', lineList) def ProcessSaleOrders(oldDateTime): response = CheckForSO(oldDateTime) saleOrders = [] if response.Detail ! = None : for x in range ( 0 , len (response.Detail)): if response.Detail.GetAt(x).ShipMethodRef.FullName.GetValue() = = 'Pick' : if not CheckForSaleOrderOdoo(response.Detail.GetAt(x)): saleOrders.append(ParseQB(response.Detail.GetAt(x))) for x in saleOrders: CreateSaleOrderOdoo(x) #Runtime----------------------------------------------------------------------------------------- while True : print ( "Checking Sales Orders" ) try : dateTime = datetime.datetime.now() - datetime.timedelta(hours = 4 , minutes = 5 ) ProcessSaleOrders(dateTime) except Exception as e: print (e) print ( "Done" ) time.sleep( 300 ) |