Skip to content

Commit

Permalink
[ADD] module sale_dropshipping makes it better to deal with purchases…
Browse files Browse the repository at this point in the history
… with known sale schemes, specially the following case:

1) normal
2) direct delivery (also called drop shipping)
3) direct invoice
4) direct delivery and direct invoice
  • Loading branch information
nbessi committed Nov 15, 2013
2 parents 8a928ce + 9873e68 commit 3fb6151
Show file tree
Hide file tree
Showing 11 changed files with 671 additions and 0 deletions.
25 changes: 25 additions & 0 deletions sale_dropshipping/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 20010 Akretion LDTA (<http://www.akretion.com>).
# @author Raphaël Valyi
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from . import purchase
from . import sale
from . import product
64 changes: 64 additions & 0 deletions sale_dropshipping/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 20010 Akretion LDTA (<http://www.akretion.com>).
# @author Raphaël Valyi
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{"name": "Sale Dropshipping",
"version": "1.0",
"author": "Akretion",
"website": "http://www.openerp.com",
"category": "Generic Modules/Purchase",
"depends": ["purchase",
"sale_stock"],
"description": """
Makes it better to deal with purchases with known sale schemes, specially the following case:
1) normal
2) direct delivery (also called drop shipping)
3) direct invoice
4) direct delivery and direct invoice
See the attached diagram in images/purchase_to_sale.png to see the difference between those flows.
In all those specific MTO (by opposition of MTS) cases,
it will link the sale order line and the purchase order lines together.
A good idea might be to use this module with the mrp_jit module
if you want MTO flows to be automatically dealt with right
at the sale order validation.
You can also tell if product suppliers accept drop shipping or not.
If they accept it and if sale order
line has more products than the virtual quantity available,
then it selects drop shipping by default.
In the out going product list view, you can filter in or out drop shipping picking.
TODO: eventually it might be interesting to do a chained move from supplier to internal location and
from internal location to customer instead of supplier o customer directly.
This would enable moves to properly generate accounting moves
in the stock journal for better tracking.
""",
"init_xml": [],
"demo_xml": [],
"test": [],
"update_xml": ["purchase_view.xml", "sale_view.xml", "product_view.xml", "stock_view.xml"],
'images': ['images/purchase_to_sale.png'],
'installable': True,
'certificate': None,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
89 changes: 89 additions & 0 deletions sale_dropshipping/i18n/pt_BR.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * purchase_to_sale
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 6.0.3\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2011-09-08 16:18+0000\n"
"PO-Revision-Date: 2011-09-08 16:18+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: purchase_to_sale
#: selection:purchase.order,sale_flow:0
msgid "Direct Invoice"
msgstr "Faturamento Direto"

#. module: purchase_to_sale
#: field:purchase.order,sale_id:0
msgid "Related Sale Order"
msgstr "Pedido de Venda Relacionado"

#. module: purchase_to_sale
#: field:purchase.order,sale_flow:0
msgid "Sale Flow"
msgstr "Fluxo de Venda"

#. module: purchase_to_sale
#: sql_constraint:purchase.order:0
msgid "Order Reference must be unique !"
msgstr "Referência de Pedido deve ser única !"

#. module: purchase_to_sale
#: selection:purchase.order,sale_flow:0
msgid "Normal"
msgstr "Normal"

#. module: purchase_to_sale
#: model:ir.module.module,description:purchase_to_sale.module_meta_information
msgid "\n"
"Makes it better to deal with purchases with known sale schemes, specially the following case:\n"
"1) normal\n"
"2) direct delivery\n"
"3) direct invoice\n"
"4) direct delivery and direct invoice\n"
" "
msgstr "\n"
"Makes it better to deal with purchases with known sale schemes, specially the following case:\n"
"1) normal\n"
"2) direct delivery\n"
"3) direct invoice\n"
"4) direct delivery and direct invoice\n"
" "

#. module: purchase_to_sale
#: field:purchase.order,analytic_account_id:0
msgid "Analytic Account"
msgstr "Centro do Custo"

#. module: purchase_to_sale
#: help:purchase.order,sale_flow:0
msgid "Is this order tied to a sale order? How will it be delivered and invoiced then?"
msgstr "Is this order tied to a sale order? How will it be delivered and invoiced then?"

#. module: purchase_to_sale
#: selection:purchase.order,sale_flow:0
msgid "Direct Delivery"
msgstr "Entrega Direta"

#. module: purchase_to_sale
#: model:ir.module.module,shortdesc:purchase_to_sale.module_meta_information
msgid "Purchase To Sale"
msgstr "Comprar para Venda"

#. module: purchase_to_sale
#: model:ir.model,name:purchase_to_sale.model_purchase_order
msgid "Purchase Order"
msgstr "Pedido de Compra"

#. module: purchase_to_sale
#: selection:purchase.order,sale_flow:0
msgid "Direct Invoice/Indirect Delivery"
msgstr "Faturamento Direto/Entrega Indireta"

Binary file added sale_dropshipping/images/purchase_to_sale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions sale_dropshipping/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 Akretion LDTA (<http://www.akretion.com>).
# @author Raphaël Valyi
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, orm


class product_supplierinfo(orm.Model):

_inherit = "product.supplierinfo"

_columns = {
"direct_delivery_flag": fields.boolean('Drop Shipping?'),
}

product_supplierinfo()


class product_product(orm.Model):

_inherit = "product.product"

def _is_direct_delivery_from_product(self, cr, uid, ids, name, arg, context=None):
res = {}

def is_direct_delivery_from_suppliers(product):
cr.execute("""SELECT direct_delivery_flag FROM product_supplierinfo
INNER JOIN res_partner ON product_supplierinfo.name = res_partner.id
WHERE product_id=%s
AND active=true ORDER BY sequence ASC LIMIT 1;""",
(product.product_tmpl_id.id,))
result = cr.fetchone()
if result and result[0]:
return True
return False

for product in self.browse(cr, uid, ids):
if 'qty' in context:
# TODO deal with partial availability?
if product.virtual_available < context['qty']:
res[product.id] = is_direct_delivery_from_suppliers(product)
else: # Available in stock
res[product.id] = False
else: # No quantity mentioned so we answer for 'any' quantity
res[product.id] = is_direct_delivery_from_suppliers(product)
return res

_columns = {'is_direct_delivery_from_product': fields.function(_is_direct_delivery_from_product,
method=True,
type='boolean',
string="Is Supplier Direct Delivery Automatic?")
}
28 changes: 28 additions & 0 deletions sale_dropshipping/product_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="product_supplierinfo_tree_view_partner_direct_delivery_tree">
<field name="name">product.supplierinfo.tree.direct_delivery.inherit</field>
<field name="model">product.supplierinfo</field>
<field name="inherit_id" ref="product.product_supplierinfo_tree_view" />
<field name="type">tree</field>
<field name="arch" type="xml">
<field position="after" name="name">
<field name="direct_delivery_flag"/>
</field>
</field>
</record>

<record model="ir.ui.view" id="product_supplierinfo_form_view_partner_direct_delivery_form">
<field name="name">product.supplierinfo.form.direct_delivery.inherit</field>
<field name="model">product.supplierinfo</field>
<field name="inherit_id" ref="product.product_supplierinfo_form_view" />
<field name="type">form</field>
<field name="arch" type="xml">
<field position="after" name="product_code">
<field name="direct_delivery_flag"/>
</field>
</field>
</record>
</data>
</openerp>
112 changes: 112 additions & 0 deletions sale_dropshipping/purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010 Akretion LDTA (<http://www.akretion.com>).
# @author Raphaël Valyi
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, orm


class purchase_order_line(orm.Model):
_inherit = "purchase.order.line"

_columns = {
'sale_order_line_id': fields.many2one('sale.order.line', 'Sale Order Line'),
}


class purchase_order(orm.Model):
_inherit = "purchase.order"

_columns = {
'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account'),
'sale_id': fields.many2one('sale.order', 'Related Sale Order'),
'sale_flow': fields.selection([('normal', 'Normal'),
('direct_delivery', 'Drop Shipping'),
('direct_invoice', 'Direct Invoice/Indirect Delivery'),
('direct_invoice_and_delivery', 'Direct Invoice')],
'Sale Flow',
help="Is this order tied to a sale order?"
" How will it be delivered and invoiced then?"),
}

_defaults = {
'sale_flow': 'normal',
}

def sale_flow_change(self, cr, uid, ids, sale_flow, sale_id,
warehouse_id, context=None):
if sale_id:
sale_obj = self.pool.get('sale.order')
partner_obj = self.pool.get('res.partner')
warehouse_obj = self.pool.get('stock.warehouse')
sale = sale_obj.browse(cr, uid, sale_id, context=context)
partner_id = sale.partner_id.id
if sale_flow in ('direct_delivery', 'direct_invoice_and_delivery'):
partner = partner_obj.browse(cr, uid, partner_id,
context=context)
address = partner.address_get(['delivery'])['delivery']
vals = {'location_id': partner.property_stock_customer.id,
'dest_address_id': address}
if sale_flow == 'direct_delivery':
vals['invoice_method'] = 'order'
else:
vals['invoice_method'] = 'picking'
return {'value': vals}
else:
warehouse = warehouse_obj.browse(cr, uid,
warehouse_id, context=context)
company_partner = warehouse.company_id.partner_id
address = company_partner.address_get(['delivery'])['delivery']
vals = {'invoice_method': 'picking',
'location_id': warehouse.lot_input_id.id,
'dest_address_id': address}
if sale_flow == 'direct_invoice':
vals['invoice_method'] = 'picking'
return {'value': vals}
return {}

def action_picking_create(self, cr, uid, ids, context=None):
res = super(purchase_order, self).action_picking_create(cr, uid, ids, context=context)
picking_obj = self.pool.get('stock.picking')
for purchase in self.browse(cr, uid, ids, context=context):
# TODO bad code inherited from OpenERP, see bug https://bugs.launchpad.net/openobject-addons/+bug/788789
if res:
if purchase.sale_flow == 'direct_delivery':
if purchase.sale_id and purchase.sale_id.order_policy == 'picking':
invoice_control = '2binvoiced'
else:
invoice_control = 'none'
picking_obj.write(
cr, uid, res,
{'type': 'out',
'invoice_state': invoice_control,
'sale_id': purchase.sale_id and purchase.sale_id.id},
context=context)
elif purchase.sale_flow == 'direct_invoice':
picking_obj.write(cr, uid, res,
{'invoice_state': 'none'},
context=context)
elif purchase.sale_flow == 'direct_invoice_and_delivery':
picking_obj.write(
cr, uid, res,
{'type': 'out',
'invoice_state': 'none',
'sale_id': purchase.sale_id and purchase.sale_id.id},
context=context)
return res
Loading

0 comments on commit 3fb6151

Please sign in to comment.