[IMP] Add invoice_state on move in stock_account and make sure it gets passed through procurement on the move
bzr revid: jco@openerp.com-20130830081648-mmfxshzl9cuk3jg6
This commit is contained in:
parent
81cb96eb92
commit
1a1338fa41
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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),
|
||||
},
|
||||
|
|
|
@ -34,11 +34,6 @@ import openerp.addons.decimal_precision as dp
|
|||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
#----------------------------------------------------------
|
||||
# Invoice state
|
||||
#----------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
|
|
|
@ -29,8 +29,18 @@
|
|||
<xpath expr="//field[@name='move_type']" position="after">
|
||||
<field name="invoice_state" groups="account.group_account_invoice"/>
|
||||
</xpath>
|
||||
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_move_form_inherit" model="ir.ui.view">
|
||||
<field name="name">stock.move.form.inherit</field>
|
||||
<field name="model">stock.move</field>
|
||||
<field name="inherit_id" ref="stock.view_move_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='picking_type_id']" position="after">
|
||||
<field name="invoice_state" groups="account.group_account_invoice"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -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'),
|
||||
|
|
Loading…
Reference in New Issue