Created
February 8, 2016 14:57
-
-
Save djgraham/2c3f34c6a27848f08963 to your computer and use it in GitHub Desktop.
This file contains 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
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