diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py
index f12e7026332..bdd8af1afd8 100644
--- a/addons/purchase/purchase.py
+++ b/addons/purchase/purchase.py
@@ -700,6 +700,7 @@ class purchase_order(osv.osv):
'origin': order.name,
'route_ids': order.picking_type_id.warehouse_id and [(6, 0, [x.id for x in order.picking_type_id.warehouse_id.route_ids])] or [],
'warehouse_id':order.picking_type_id.warehouse_id.id,
+ 'invoice_state': order.invoice_method == 'picking' and '2binvoiced' or 'none'
}
diff_quantity = order_line.product_qty
@@ -709,9 +710,10 @@ class purchase_order(osv.osv):
tmp.update({
'product_uom_qty': min(procurement_qty, diff_quantity),
'product_uos_qty': min(procurement_qty, diff_quantity),
- 'move_dest_id': procurement.move_dest_id.id, # blabla
- 'group_id': procurement.group_id.id or group_id, # blabla to check ca devrait etre bon et groupé dans le meme picking qd meme
+ 'move_dest_id': procurement.move_dest_id.id, #move destination is same as procurement destination
+ 'group_id': procurement.group_id.id or group_id, #move group is same as group of procurements if it exists, otherwise take another group
'procurement_id': procurement.id,
+ 'invoice_state': procurement.rule_id.invoice_state or (procurement.location_id and procurement.location_id.usage == 'customer' and procurement.invoice_state) or (order.invoice_method == 'picking' and '2binvoiced') or 'none', #dropship case takes from sale
})
diff_quantity -= min(procurement_qty, diff_quantity)
res.append(tmp)
diff --git a/addons/stock_account/__openerp__.py b/addons/stock_account/__openerp__.py
index a2dab1289f4..5c67002f61f 100644
--- a/addons/stock_account/__openerp__.py
+++ b/addons/stock_account/__openerp__.py
@@ -53,6 +53,7 @@ Dashboard / Reports for Warehouse Management includes:
'wizard/stock_change_standard_price_view.xml',
'wizard/stock_invoice_onshipping_view.xml',
'wizard/stock_valuation_history_view.xml',
+ 'wizard/stock_return_picking_view.xml',
'product_data.xml',
'product_view.xml',
'stock_account_view.xml',
diff --git a/addons/stock_account/stock.py b/addons/stock_account/stock.py
index db08ba39eb4..44590353e1b 100644
--- a/addons/stock_account/stock.py
+++ b/addons/stock_account/stock.py
@@ -27,11 +27,10 @@ class stock_location_path(osv.osv):
'invoice_state': fields.selection([
("invoiced", "Invoiced"),
("2binvoiced", "To Be Invoiced"),
- ("none", "Not Applicable")], "Invoice Status",
- required=True,),
+ ("none", "Not Applicable")], "Invoice Status",),
}
_defaults = {
- 'invoice_state': 'none',
+ 'invoice_state': '',
}
#----------------------------------------------------------
@@ -43,11 +42,10 @@ class procurement_rule(osv.osv):
'invoice_state': fields.selection([
("invoiced", "Invoiced"),
("2binvoiced", "To Be Invoiced"),
- ("none", "Not Applicable")], "Invoice Status",
- required=True),
+ ("none", "Not Applicable")], "Invoice Status",),
}
_defaults = {
- 'invoice_state': 'none',
+ 'invoice_state': '',
}
#----------------------------------------------------------
@@ -61,16 +59,16 @@ class procurement_order(osv.osv):
'invoice_state': fields.selection([("invoiced", "Invoiced"),
("2binvoiced", "To Be Invoiced"),
("none", "Not Applicable")
- ], "Invoice Control", required=True),
+ ], "Invoice Control"),
}
def _run_move_create(self, cr, uid, procurement, context=None):
res = super(procurement_order, self)._run_move_create(cr, uid, procurement, context=context)
- res.update({'invoice_state': (procurement.rule_id.invoice_state in ('none', False) and procurement.invoice_state or procurement.rule_id.invoice_state) or 'none'})
+ res.update({'invoice_state': procurement.rule_id.invoice_state or procurement.invoice_state or 'none'})
return res
_defaults = {
- 'invoice_state': 'none'
+ 'invoice_state': ''
}
@@ -92,7 +90,7 @@ class stock_move(osv.osv):
}
def _get_master_data(self, cr, uid, move, company, context=None):
- ''' returns a tupple (browse_record(res.partner), ID(res.users), ID(res.currency)'''
+ ''' returns a tuple (browse_record(res.partner), ID(res.users), ID(res.currency)'''
return move.picking_id.partner_id, uid, company.currency_id.id
def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
diff --git a/addons/stock_account/stock_account_view.xml b/addons/stock_account/stock_account_view.xml
index 3b3ab37b212..867f2eaee34 100644
--- a/addons/stock_account/stock_account_view.xml
+++ b/addons/stock_account/stock_account_view.xml
@@ -32,8 +32,8 @@
-
-
+
+
diff --git a/addons/stock_account/wizard/__init__.py b/addons/stock_account/wizard/__init__.py
index 87f0841e3c5..09d08bb82d1 100644
--- a/addons/stock_account/wizard/__init__.py
+++ b/addons/stock_account/wizard/__init__.py
@@ -22,3 +22,4 @@
import stock_change_standard_price
import stock_invoice_onshipping
import stock_valuation_history
+import stock_return_picking
diff --git a/addons/stock_account/wizard/stock_invoice_onshipping.py b/addons/stock_account/wizard/stock_invoice_onshipping.py
index f600b28f585..b0a98c75dc6 100644
--- a/addons/stock_account/wizard/stock_invoice_onshipping.py
+++ b/addons/stock_account/wizard/stock_invoice_onshipping.py
@@ -33,12 +33,32 @@ class stock_invoice_onshipping(osv.osv_memory):
if context is None:
context = {}
journal_obj = self.pool.get('account.journal')
- value = journal_obj.search(cr, uid, [('type', 'in',('sale','sale_Refund'))])
+ res_ids = context and context.get('active_ids', [])
+ pick_obj = self.pool.get('stock.picking')
+ pickings = pick_obj.browse(cr, uid, res_ids, context=context)
vals = []
- for jr_type in journal_obj.browse(cr, uid, value, context=context):
- t1 = jr_type.id,jr_type.name
- if t1 not in vals:
- vals.append(t1)
+ for pick in pickings:
+ if not pick.move_lines:
+ continue
+ src_usage = pick.move_lines[0].location_id.usage
+ dest_usage = pick.move_lines[0].location_dest_id.usage
+ type = pick.picking_type_id.code
+ if type == 'outgoing' and dest_usage == 'supplier':
+ journal_type = 'purchase_refund'
+ elif type == 'outgoing' and dest_usage == 'customer':
+ journal_type = 'sale'
+ elif type == 'incoming' and src_usage == 'supplier':
+ journal_type = 'purchase'
+ elif type == 'incoming' and src_usage == 'customer':
+ journal_type = 'sale_refund'
+ else:
+ journal_type = 'sale'
+ journals = journal_obj.search(cr, uid, [('type', '=', journal_type)])
+ for jr_type in journal_obj.browse(cr, uid, journals, context=context):
+ t1 = str(jr_type.id),jr_type.name
+ print t1
+ if t1 not in vals:
+ vals.append(t1)
return vals
_name = "stock.invoice.onshipping"
@@ -48,6 +68,7 @@ class stock_invoice_onshipping(osv.osv_memory):
'group': fields.boolean("Group by partner"),
'inv_type': fields.selection([('out_invoice','Create Invoice'),('out_refund','Refund Invoice')], "Invoice Type"),
'invoice_date': fields.date('Invoice Date'),
+ #'inv_t': fields.selection([('in_invoice', ''), ]),
}
_defaults = {
'journal_id' : _get_journal,
@@ -71,21 +92,28 @@ class stock_invoice_onshipping(osv.osv_memory):
def open_invoice(self, cr, uid, ids, context=None):
if context is None:
context = {}
+
invoice_ids = self.create_invoice(cr, uid, ids, context=context)
if not invoice_ids:
raise osv.except_osv(_('Error!'), _('No invoice created!'))
- onshipdata_obj = self.read(cr, uid, ids, ['journal_id', 'group', 'invoice_date', 'inv_type'])
- inv_type = onshipdata_obj[0]['inv_type']
+ data = self.browse(cr, uid, ids[0], context=context)
action_model = False
action = {}
-
+ acc_journal = self.pool.get("account.journal")
+ journal = acc_journal.browse(cr, uid, int(data.journal_id), context=context)
+ journal2type = {'sale':'out_invoice', 'purchase':'in_invoice' , 'sale_refund':'out_refund', 'purchase_refund':'in_refund'}
+ inv_type = journal2type.get(journal.type) or 'out_invoice'
data_pool = self.pool.get('ir.model.data')
- if inv_type == "out_refund":
- action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree3")
- elif inv_type == "out_invoice":
+ if inv_type == "out_invoice":
action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree1")
+ elif inv_type == "in_invoice":
+ action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree2")
+ elif inv_type == "out_refund":
+ action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree3")
+ elif inv_type == "in_refund":
+ action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree4")
if action_model:
action_pool = self.pool[action_model]
@@ -97,18 +125,18 @@ class stock_invoice_onshipping(osv.osv_memory):
def create_invoice(self, cr, uid, ids, context=None):
context = context or {}
picking_pool = self.pool.get('stock.picking')
- onshipdata_obj = self.read(cr, uid, ids, ['journal_id', 'group', 'invoice_date', 'inv_type'])
-
- context['date_inv'] = onshipdata_obj[0]['invoice_date']
- inv_type = onshipdata_obj[0]['inv_type']
+ data = self.browse(cr, uid, ids[0])
+ journal2type = {'sale':'out_invoice', 'purchase':'in_invoice', 'sale_refund':'out_refund', 'purchase_refund':'in_refund'}
+ context['date_inv'] = data.invoice_date
+ acc_journal = self.pool.get("account.journal")
+ journal = acc_journal.browse(cr, uid, int(data.journal_id), context=context)
+ inv_type = journal2type.get(journal.type) or 'out_invoice'
context['inv_type'] = inv_type
active_ids = context.get('active_ids', [])
- if isinstance(onshipdata_obj[0]['journal_id'], tuple):
- onshipdata_obj[0]['journal_id'] = onshipdata_obj[0]['journal_id'][0]
res = picking_pool.action_invoice_create(cr, uid, active_ids,
- journal_id = onshipdata_obj[0]['journal_id'],
- group = onshipdata_obj[0]['group'],
+ journal_id = data.journal_id,
+ group = data.group,
type = inv_type,
context=context)
return res
diff --git a/addons/stock_account/wizard/stock_invoice_onshipping_view.xml b/addons/stock_account/wizard/stock_invoice_onshipping_view.xml
index a37af929576..75892694bfa 100644
--- a/addons/stock_account/wizard/stock_invoice_onshipping_view.xml
+++ b/addons/stock_account/wizard/stock_invoice_onshipping_view.xml
@@ -23,17 +23,6 @@
-
-
-
).
+#
+# 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 .
+#
+##############################################################################
+
+from openerp.osv import osv, fields
+from openerp.tools.translate import _
+import openerp.addons.decimal_precision as dp
+
+
+class stock_return_picking(osv.osv_memory):
+ _inherit = 'stock.return.picking'
+ _columns = {
+ 'invoice_state': fields.selection([('2binvoiced', 'To be refunded/invoiced'), ('none', 'No invoicing')], 'Invoicing',required=True),
+ }
+
+ def default_get(self, cr, uid, fields, context=None):
+ res = super(stock_return_picking, self).default_get(cr, uid, fields, context=context)
+ record_id = context and context.get('active_id', False) or False
+ pick_obj = self.pool.get('stock.picking')
+ pick = pick_obj.browse(cr, uid, record_id, context=context)
+ if pick:
+ if 'invoice_state' in fields:
+ if pick.invoice_state=='invoiced':
+ res.update({'invoice_state': '2binvoiced'})
+ else:
+ res.update({'invoice_state': 'none'})
+ return res
+
+
+
+ def _create_returns(self, cr, uid, ids, context=None):
+ if context is None:
+ context = {}
+ data = self.browse(cr, uid, ids[0], context=context)
+ new_picking, picking_type_id = super(stock_return_picking, self)._create_returns(cr, uid, ids, context=context)
+ if data.invoice_state == '2binvoiced':
+ pick_obj = self.pool.get("stock.picking")
+ move_obj = self.pool.get("stock.move")
+ move_ids = [x.id for x in pick_obj.browse(cr, uid, new_picking, context=context).move_lines]
+ move_obj.write(cr, uid, move_ids, {'invoice_state': '2binvoiced'})
+ return new_picking, picking_type_id
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/stock_account/wizard/stock_return_picking_view.xml b/addons/stock_account/wizard/stock_return_picking_view.xml
new file mode 100644
index 00000000000..8365c424b95
--- /dev/null
+++ b/addons/stock_account/wizard/stock_return_picking_view.xml
@@ -0,0 +1,14 @@
+
+
+
+ Return lines
+ stock.return.picking
+
+
+
+
+
+
+
+
+