diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py
index 015347449ae..055b4309d6d 100644
--- a/addons/sale_stock/sale_stock.py
+++ b/addons/sale_stock/sale_stock.py
@@ -168,11 +168,12 @@ class sale_order(osv.osv):
# if order_policy<>picking: super()
# else: call invoice_on_picking_method()
def action_invoice_create(self, cr, uid, ids, grouped=False, states=['confirmed', 'done', 'exception'], date_invoice = False, context=None):
- picking_obj = self.pool.get('stock.picking')
+ move_obj = self.pool.get("stock.move")
res = super(sale_order,self).action_invoice_create(cr, uid, ids, grouped=grouped, states=states, date_invoice = date_invoice, context=context)
for order in self.browse(cr, uid, ids, context=context):
if order.order_policy == 'picking':
- picking_obj.write(cr, uid, map(lambda x: x.id, order.picking_ids), {'invoice_state': 'invoiced'})
+ for picking in order.picking_ids:
+ move_obj.write(cr, uid, [x.id for x in picking.move_lines], {'invoice_state': 'invoiced'}, context=context)
return res
def action_cancel(self, cr, uid, ids, context=None):
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 7ece3c202dc..819762b06c2 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1130,7 +1130,10 @@ class stock_move(osv.osv):
'origin_returned_move_id': fields.many2one('stock.move', 'Origin return move', help='move that created the return move'),
'returned_move_ids': fields.one2many('stock.move', 'origin_returned_move_id', 'All returned moves', help='Optional: all returned moves created from this move'),
'availability': fields.function(_get_product_availability, type='float', string='Availability'),
- }
+ }
+
+
+
def copy(self, cr, uid, id, default=None, context=None):
if default is None:
diff --git a/addons/stock_account/stock.py b/addons/stock_account/stock.py
index e404ab3dd7b..312b1668f6d 100644
--- a/addons/stock_account/stock.py
+++ b/addons/stock_account/stock.py
@@ -22,6 +22,55 @@
from openerp.osv import fields, osv
from openerp.tools.translate import _
+#----------------------------------------------------------
+# Procurement Rule
+#----------------------------------------------------------
+class procurement_rule(osv.osv):
+ _inherit = 'procurement.rule'
+ _columns= {
+ 'invoice_state': fields.selection([
+ ("invoiced", "Invoiced"),
+ ("2binvoiced", "To Be Invoiced"),
+ ("none", "Not Applicable")], "Invoice Status",
+ required=False),
+ }
+
+#----------------------------------------------------------
+# Procurement Order
+#----------------------------------------------------------
+
+
+class procurement_order(osv.osv):
+ _inherit = "procurement.order"
+
+ 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 })
+ return res
+
+
+#----------------------------------------------------------
+# Move
+#----------------------------------------------------------
+
+class stock_move(osv.osv):
+ _inherit = "stock.move"
+ _columns = {
+ 'invoice_state': fields.selection([("invoiced", "Invoiced"),
+ ("2binvoiced", "To Be Invoiced"),
+ ("none", "Not Applicable")], "Invoice Control",
+ select=True, required=True, track_visibility='onchange',
+ states={'draft': [('readonly', False)]}),
+ }
+ _defaults= {
+ 'invoice_state': lambda *args, **argv: 'none'
+ }
+
+
+
+#----------------------------------------------------------
+# Picking
+#----------------------------------------------------------
class stock_picking(osv.osv):
_inherit = 'stock.picking'
@@ -30,22 +79,13 @@ class stock_picking(osv.osv):
for pick in self.browse(cr, uid, ids, context=context):
result[pick.id] = 'none'
for move in pick.move_lines:
- if move.procurement_id:
- if move.procurement_id.invoice_state=='invoiced':
- result[pick.id] = 'invoiced'
- elif move.procurement_id.invoice_state=='2binvoiced':
- result[pick.id] = '2binvoiced'
- break
+ if move.invoice_state=='invoiced':
+ result[pick.id] = 'invoiced'
+ elif move.invoice_state=='2binvoiced':
+ result[pick.id] = '2binvoiced'
+ break
return result
- def __get_picking_procurement(self, cr, uid, ids, context={}):
- result = {}
- for proc in self.pool.get('procurement.order').browse(cr, uid, ids, context=context):
- for move in proc.move_ids:
- if move.picking_id:
- result[move.picking_id.id] = True
- return result.keys()
-
def __get_picking_move(self, cr, uid, ids, context={}):
res = []
for move in self.pool.get('stock.move').browse(cr, uid, ids, context=context):
@@ -59,8 +99,8 @@ class stock_picking(osv.osv):
("2binvoiced", "To Be Invoiced"),
("none", "Not Applicable")
], string="Invoice Control", required=True,
+
store={
- 'procurement.order': (__get_picking_procurement, ['invoice_state'], 10),
'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['state'], 10),
'stock.move': (__get_picking_move, ['picking_id'], 10),
},
diff --git a/addons/stock_account/stock_account.py b/addons/stock_account/stock_account.py
index f9e62fa80e2..659f53adf91 100644
--- a/addons/stock_account/stock_account.py
+++ b/addons/stock_account/stock_account.py
@@ -34,11 +34,6 @@ import openerp.addons.decimal_precision as dp
import logging
_logger = logging.getLogger(__name__)
-#----------------------------------------------------------
-# Invoice state
-#----------------------------------------------------------
-
-
#----------------------------------------------------------
diff --git a/addons/stock_account/stock_account_view.xml b/addons/stock_account/stock_account_view.xml
index a7e6bc8afe9..c6f9a581858 100644
--- a/addons/stock_account/stock_account_view.xml
+++ b/addons/stock_account/stock_account_view.xml
@@ -29,8 +29,18 @@
-
+
+
+ stock.move.form.inherit
+ stock.move
+
+
+
+
+
+
+
diff --git a/addons/stock_location/stock_location.py b/addons/stock_location/stock_location.py
index 2cdffdad785..fc36d48d7f9 100644
--- a/addons/stock_location/stock_location.py
+++ b/addons/stock_location/stock_location.py
@@ -133,11 +133,7 @@ class procurement_rule(osv.osv):
'delay': fields.integer('Number of Hours'),
'procure_method': fields.selection([('make_to_stock','Make to Stock'),('make_to_order','Make to Order')], 'Procure Method', required=True, help="'Make to Stock': When needed, take from the stock or wait until re-supplying. 'Make to Order': When needed, purchase or produce for the procurement request."),
'partner_address_id': fields.many2one('res.partner', 'Partner Address'),
- 'invoice_state': fields.selection([
- ("invoiced", "Invoiced"),
- ("2binvoiced", "To Be Invoiced"),
- ("none", "Not Applicable")], "Invoice Status",
- required=True,),
+
'route_sequence': fields.related('route_id', 'sequence', string='Route Sequence', store={'stock.location.route': (_get_rules, ['sequence'], 10)}),
'sequence': fields.integer('Sequence'),
'propagate': fields.boolean('Propagate cancel and split', help='If checked, when the previous move of the move (which was generated by a next procurement) is cancelled or split, the move generated by this move will too'),