Skip to content

Instantly share code, notes, and snippets.

@djgraham
Created February 8, 2016 14:57
Show Gist options
  • Save djgraham/2c3f34c6a27848f08963 to your computer and use it in GitHub Desktop.
Save djgraham/2c3f34c6a27848f08963 to your computer and use it in GitHub Desktop.
module SpreeOdoo
class StockMovementPush
attr_reader :spree_variant, :stats, :gateway, :reference, :qty
def initialize(ooor, spree_variant, qty, reference, opts = {})
@gateway = ooor
@stats = { total: 0, found: 0, adjusted: 0, errors: [] }
@spree_variant = spree_variant
@reference = reference
@qty = qty
end
def execute
sm = StockMove.create(
product_id: odoo_product.id,
picking_type_id: stock_picking_type.id,
location_id: source_location.id,
location_dest_id: destination_location.id,
product_uom_qty: qty,
product_uom: 1,
name: "Spree Order: [#{reference}]",
priority: '2'
)
end
private
#finders required for the actual stock move
def odoo_product
ProductProduct.find(default_code: spree_variant.sku).first
end
def source_location(name: 'Internet')
StockLocation.find(name: name).first
end
def destination_location(name: 'Customers')
StockLocation.find(name: name).first
end
def stock_picking_type(name: 'Websales')
StockPickingType.find(name: name).first
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment