commit
9477f28cd3
|
@ -67,3 +67,4 @@
|
|||
"access_stock_picking_mrp_manager","stock.picking mrp_manager","stock.model_stock_picking","mrp.group_mrp_manager",1,0,0,0
|
||||
"access_report_mrp_inout_user","report.mrp.inout user","model_report_mrp_inout","mrp.group_mrp_user",1,0,0,0
|
||||
"access_report_workcenter_load_user","report.workcenter.load.user","model_report_workcenter_load","mrp.group_mrp_user",1,0,0,0
|
||||
"access_mrp_bom","mrp.bom","model_mrp_bom","base.group_sale_salesman",1,0,0,0
|
||||
|
|
|
|
@ -1,5 +1,5 @@
|
|||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||
"access_sale_shop","sale.shop","model_sale_shop","base.group_user",1,0,0,0
|
||||
"access_sale_shop","sale.shop","model_sale_shop","base.group_user",1,1,0,0
|
||||
"access_sale_order","sale.order","model_sale_order","base.group_sale_salesman",1,1,1,0
|
||||
"access_sale_order_line","sale.order.line","model_sale_order_line","base.group_sale_salesman",1,1,1,1
|
||||
"access_account_invoice_tax_salesman","account_invoice_tax salesman","account.model_account_invoice_tax","base.group_sale_salesman",1,1,1,0
|
||||
|
|
|
|
@ -930,6 +930,25 @@ class stock_picking(osv.osv):
|
|||
'''Call after the creation of the invoice'''
|
||||
return
|
||||
|
||||
def _get_invoice_type(self, pick):
|
||||
src_usage = dest_usage = None
|
||||
inv_type = None
|
||||
if pick.invoice_state == '2binvoiced':
|
||||
if pick.move_lines:
|
||||
src_usage = pick.move_lines[0].location_id.usage
|
||||
dest_usage = pick.move_lines[0].location_dest_id.usage
|
||||
if pick.type == 'out' and dest_usage == 'supplier':
|
||||
inv_type = 'in_refund'
|
||||
elif pick.type == 'out' and dest_usage == 'customer':
|
||||
inv_type = 'out_invoice'
|
||||
elif pick.type == 'in' and src_usage == 'supplier':
|
||||
inv_type = 'in_invoice'
|
||||
elif pick.type == 'in' and src_usage == 'customer':
|
||||
inv_type = 'out_refund'
|
||||
else:
|
||||
inv_type = 'out_invoice'
|
||||
return inv_type
|
||||
|
||||
def action_invoice_create(self, cr, uid, ids, journal_id=False,
|
||||
group=False, type='out_invoice', context=None):
|
||||
""" Creates invoice based on the invoice state selected for picking.
|
||||
|
@ -945,7 +964,7 @@ class stock_picking(osv.osv):
|
|||
invoice_line_obj = self.pool.get('account.invoice.line')
|
||||
invoices_group = {}
|
||||
res = {}
|
||||
|
||||
inv_type = type
|
||||
for picking in self.browse(cr, uid, ids, context=context):
|
||||
if picking.invoice_state != '2binvoiced':
|
||||
continue
|
||||
|
@ -954,8 +973,11 @@ class stock_picking(osv.osv):
|
|||
if not partner:
|
||||
raise osv.except_osv(_('Error, no partner !'),
|
||||
_('Please put a partner on the picking list if you want to generate invoice.'))
|
||||
|
||||
if not inv_type:
|
||||
inv_type = self._get_invoice_type(picking)
|
||||
|
||||
if type in ('out_invoice', 'out_refund'):
|
||||
if inv_type in ('out_invoice', 'out_refund'):
|
||||
account_id = partner.property_account_receivable.id
|
||||
payment_term_id = self._get_payment_term(cr, uid, picking)
|
||||
else:
|
||||
|
@ -980,7 +1002,7 @@ class stock_picking(osv.osv):
|
|||
invoice_vals = {
|
||||
'name': picking.name,
|
||||
'origin': (picking.name or '') + (picking.origin and (':' + picking.origin) or ''),
|
||||
'type': type,
|
||||
'type': inv_type,
|
||||
'account_id': account_id,
|
||||
'partner_id': partner.id,
|
||||
'address_invoice_id': address_invoice_id,
|
||||
|
@ -1012,7 +1034,7 @@ class stock_picking(osv.osv):
|
|||
else:
|
||||
name = move_line.name
|
||||
|
||||
if type in ('out_invoice', 'out_refund'):
|
||||
if inv_type in ('out_invoice', 'out_refund'):
|
||||
account_id = move_line.product_id.product_tmpl_id.\
|
||||
property_account_income.id
|
||||
if not account_id:
|
||||
|
@ -1026,14 +1048,14 @@ class stock_picking(osv.osv):
|
|||
property_account_expense_categ.id
|
||||
|
||||
price_unit = self._get_price_unit_invoice(cr, uid,
|
||||
move_line, type)
|
||||
move_line, inv_type)
|
||||
discount = self._get_discount_invoice(cr, uid, move_line)
|
||||
tax_ids = self._get_taxes_invoice(cr, uid, move_line, type)
|
||||
tax_ids = self._get_taxes_invoice(cr, uid, move_line, inv_type)
|
||||
account_analytic_id = self._get_account_analytic_invoice(cr, uid, picking, move_line)
|
||||
|
||||
#set UoS if it's a sale and the picking doesn't have one
|
||||
uos_id = move_line.product_uos and move_line.product_uos.id or False
|
||||
if not uos_id and type in ('out_invoice', 'out_refund'):
|
||||
if not uos_id and inv_type in ('out_invoice', 'out_refund'):
|
||||
uos_id = move_line.product_uom.id
|
||||
|
||||
account_id = self.pool.get('account.fiscal.position').map_account(cr, uid, partner.property_account_position, account_id)
|
||||
|
@ -1053,7 +1075,7 @@ class stock_picking(osv.osv):
|
|||
self._invoice_line_hook(cr, uid, move_line, invoice_line_id)
|
||||
|
||||
invoice_obj.button_compute(cr, uid, [invoice_id], context=context,
|
||||
set_total=(type in ('in_invoice', 'in_refund')))
|
||||
set_total=(inv_type in ('in_invoice', 'in_refund')))
|
||||
self.write(cr, uid, [picking.id], {
|
||||
'invoice_state': 'invoiced',
|
||||
}, context=context)
|
||||
|
@ -1480,7 +1502,7 @@ class stock_move(osv.osv):
|
|||
'move_dest_id': fields.many2one('stock.move', 'Destination Move', help="Optional: next stock move when chaining them", select=True),
|
||||
'move_history_ids': fields.many2many('stock.move', 'stock_move_history_ids', 'parent_id', 'child_id', 'Move History (child moves)'),
|
||||
'move_history_ids2': fields.many2many('stock.move', 'stock_move_history_ids', 'child_id', 'parent_id', 'Move History (parent moves)'),
|
||||
'picking_id': fields.many2one('stock.picking', 'Picking List', select=True,states={'done': [('readonly', True)]}),
|
||||
'picking_id': fields.many2one('stock.picking', 'Reference', select=True,states={'done': [('readonly', True)]}),
|
||||
'note': fields.text('Notes'),
|
||||
'state': fields.selection([('draft', 'Draft'), ('waiting', 'Waiting'), ('confirmed', 'Confirmed'), ('assigned', 'Available'), ('done', 'Done'), ('cancel', 'Cancelled')], 'State', readonly=True, select=True,
|
||||
help='When the stock move is created it is in the \'Draft\' state.\n After that it is set to \'Confirmed\' state.\n If stock is available state is set to \'Available\'.\n When the picking is done the state is \'Done\'.\
|
||||
|
@ -2231,7 +2253,7 @@ class stock_move(osv.osv):
|
|||
quantity_rest = quantity
|
||||
uos_qty_rest = uos_qty
|
||||
if move.product_id.track_production and location_id:
|
||||
res += self.split_lines(cr, uid, [move.id], quantity_rest, split_by_qty=1, context=context)
|
||||
res += self.action_split(cr, uid, [move.id], quantity_rest, split_by_qty=1, context=context)
|
||||
else:
|
||||
res += [move.id]
|
||||
update_val = {
|
||||
|
|
|
@ -304,7 +304,7 @@
|
|||
<page string="Stock Moves">
|
||||
<field colspan="2" name="move_ids" nolabel="1" widget="one2many_list">
|
||||
<tree string="Stock Moves">
|
||||
<field name="picking_id" string="Reference"/>
|
||||
<field name="picking_id" string="Reference"/>
|
||||
<field name="origin"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="product_id"/>
|
||||
|
@ -317,7 +317,7 @@
|
|||
<field name="location_dest_id"/>
|
||||
<field name="state"/>
|
||||
</tree>
|
||||
</field>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
|
@ -449,7 +449,7 @@
|
|||
<group col="2" colspan="2" groups="base.group_extended">
|
||||
<separator string="Chained Locations" colspan="2"/>
|
||||
<field name="chained_location_type"/>
|
||||
<field name="chained_location_id"/>
|
||||
<field name="chained_location_id" attrs="{'required':[('chained_location_type','=','fixed')]}"/>
|
||||
<field name="chained_auto_packing"/>
|
||||
<field name="chained_delay"/>
|
||||
<field name="chained_journal_id"/>
|
||||
|
@ -726,7 +726,7 @@
|
|||
<button name="action_assign" states="confirmed" string="Check Availability" type="object" icon="gtk-find"/>
|
||||
<button name="force_assign" states="confirmed" string="Force Availability" type="object" icon="gtk-jump-to"/>
|
||||
<button name="action_process" states="assigned" string="Process" type="object" icon="gtk-go-forward"/>
|
||||
<button states="done" name="%(action_stock_invoice_onshipping)d" string="Create Invoice" type="action" icon="terp-gtk-go-back-rtl" attrs="{'invisible':[('invoice_state','!=','2binvoiced')]}"/>
|
||||
<button states="done" name="%(action_stock_invoice_onshipping)d" string="Create Invoice" type="action" icon="terp-gtk-go-back-rtl" />
|
||||
</group>
|
||||
</page>
|
||||
<page string="Additional info" groups="base.group_extended,base.group_multi_company">
|
||||
|
@ -919,7 +919,7 @@
|
|||
<button name="action_assign" states="confirmed" string="Check Availability" type="object" groups="base.group_extended" icon="gtk-find"/>
|
||||
<button name="force_assign" states="confirmed" string="Force Availability" type="object" icon="gtk-jump-to"/>
|
||||
<button name="action_process" states="assigned" string="Process" type="object" icon="gtk-go-forward"/>
|
||||
<button name="%(action_stock_invoice_onshipping)d" string="Create Invoice" states="done" type="action" icon="terp-gtk-go-back-rtl" attrs="{'invisible':[('invoice_state','!=','2binvoiced')]}"/>
|
||||
<button name="%(action_stock_invoice_onshipping)d" string="Create Invoice" states="done" type="action" icon="terp-gtk-go-back-rtl"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Additional info" groups="base.group_extended,base.group_multi_company">
|
||||
|
@ -1139,7 +1139,7 @@
|
|||
<button name="force_assign" states="confirmed" string="Force Availability" type="object" groups="base.group_extended" icon="gtk-jump-to"/>
|
||||
<button name="action_process" states="assigned" string="Process" type="object" icon="gtk-go-forward"/>
|
||||
<group colspan="1" states="done">
|
||||
<button name="%(action_stock_invoice_onshipping)d" string="Create Invoice" type="action" icon="terp-gtk-go-back-rtl" attrs="{'invisible':[('invoice_state','!=','2binvoiced')]}"/>
|
||||
<button name="%(action_stock_invoice_onshipping)d" string="Create Invoice" type="action" icon="terp-gtk-go-back-rtl"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
|
@ -1461,9 +1461,9 @@
|
|||
Reception Picking (By Stock Move)
|
||||
====================================
|
||||
<!-- from stock_partial_move_view -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<record id="view_move_tree_reception_picking" model="ir.ui.view">
|
||||
<field name="name">stock.move.tree2</field>
|
||||
<field name="model">stock.move</field>
|
||||
|
@ -1523,7 +1523,7 @@
|
|||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
<record id="view_move_form_reception_picking" model="ir.ui.view">
|
||||
<field name="name">stock.move.form2</field>
|
||||
|
|
|
@ -24,14 +24,52 @@ from osv import fields, osv
|
|||
from tools.translate import _
|
||||
|
||||
class stock_invoice_onshipping(osv.osv_memory):
|
||||
|
||||
def _get_journal_id(self, cr, uid, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
model = context.get('active_model')
|
||||
if not model or model != 'stock.picking':
|
||||
return []
|
||||
|
||||
model_pool = self.pool.get(model)
|
||||
acct_obj = self.pool.get('account.journal')
|
||||
res_ids = context and context.get('active_ids', [])
|
||||
vals=[]
|
||||
pick_types = list(set(map(lambda x: x.type, model_pool.browse(cr, uid, res_ids, context=context))))
|
||||
for type in pick_types:
|
||||
if type == 'out':
|
||||
value = acct_obj.search(cr, uid, [('type', 'in',('sale','sale_refund') )])
|
||||
for jr_type in acct_obj.browse(cr, uid, value, context=context):
|
||||
t1 = jr_type.id,jr_type.name
|
||||
vals.append(t1)
|
||||
|
||||
elif type == 'in':
|
||||
value = acct_obj.search(cr, uid, [('type', 'in',('purchase','purchase_refund') )])
|
||||
for jr_type in acct_obj.browse(cr, uid, value, context=context):
|
||||
t1 = jr_type.id,jr_type.name
|
||||
vals.append(t1)
|
||||
else:
|
||||
value = acct_obj.search(cr, uid, [('type', 'in',('cash','bank','general','situation') )])
|
||||
for jr_type in acct_obj.browse(cr, uid, value, context=context):
|
||||
t1 = jr_type.id,jr_type.name
|
||||
vals.append(t1)
|
||||
return vals
|
||||
|
||||
|
||||
_name = "stock.invoice.onshipping"
|
||||
_description = "Stock Invoice Onshipping"
|
||||
|
||||
|
||||
_columns = {
|
||||
'journal_id': fields.many2one('account.journal', 'Destination Journal', required=True),
|
||||
# 'journal_id': fields.many2one('account.journal', 'Destination Journal', required=True,selection=_get_journal_id),
|
||||
'journal_id': fields.selection(_get_journal_id, 'Destination Journal',required=True),
|
||||
'group': fields.boolean("Group by partner"),
|
||||
'invoice_date': fields.date('Invoiced date'),
|
||||
}
|
||||
|
||||
|
||||
def view_init(self, cr, uid, fields_list, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
@ -48,30 +86,13 @@ class stock_invoice_onshipping(osv.osv_memory):
|
|||
raise osv.except_osv(_('Warning !'), _('None of these picking lists require invoicing.'))
|
||||
return res
|
||||
|
||||
def _get_type(self, pick):
|
||||
src_usage = dest_usage = None
|
||||
pick_type = None
|
||||
if pick.invoice_state=='2binvoiced':
|
||||
if pick.move_lines:
|
||||
src_usage = pick.move_lines[0].location_id.usage
|
||||
dest_usage = pick.move_lines[0].location_dest_id.usage
|
||||
if pick.type == 'out' and dest_usage == 'supplier':
|
||||
pick_type = 'in_refund'
|
||||
elif pick.type == 'out' and dest_usage == 'customer':
|
||||
pick_type = 'out_invoice'
|
||||
elif pick.type == 'in' and src_usage == 'supplier':
|
||||
pick_type = 'in_invoice'
|
||||
elif pick.type == 'in' and src_usage == 'customer':
|
||||
pick_type = 'out_refund'
|
||||
else:
|
||||
pick_type = 'out_invoice'
|
||||
return pick_type
|
||||
|
||||
|
||||
def create_invoice(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
result = []
|
||||
picking_obj = self.pool.get('stock.picking')
|
||||
picking_pool = self.pool.get('stock.picking')
|
||||
data_pool = self.pool.get('ir.model.data')
|
||||
onshipdata_obj = self.read(cr, uid, ids[0], ['journal_id', 'group', 'invoice_date'])
|
||||
if context.get('new_picking', False):
|
||||
onshipdata_obj['id'] = onshipdata_obj.new_picking
|
||||
|
@ -79,33 +100,33 @@ class stock_invoice_onshipping(osv.osv_memory):
|
|||
|
||||
context['date_inv'] = onshipdata_obj['invoice_date']
|
||||
invoice_ids = []
|
||||
for picking in picking_obj.browse(cr, uid, context.get('active_ids', []), context=context):
|
||||
if picking.invoice_state == '2binvoiced':
|
||||
res = picking_obj.action_invoice_create(cr, uid, [picking.id],
|
||||
journal_id = onshipdata_obj['journal_id'],
|
||||
group=onshipdata_obj['group'],
|
||||
type=self._get_type(picking),
|
||||
context=context)
|
||||
invoice_ids.extend(res.values())
|
||||
context['journal_type'] = {
|
||||
'out_invoice': 'sale',
|
||||
'out_refund': 'sale_refund',
|
||||
'in_invoice': 'purchase',
|
||||
'in_refund': 'purchase_refund'
|
||||
}.get(self._get_type(picking), 'sale')
|
||||
active_ids = context.get('active_ids', [])
|
||||
active_picking = picking_pool.browse(cr, uid, context.get('active_id',False), context=context)
|
||||
inv_type = picking_pool._get_invoice_type(active_picking)
|
||||
|
||||
res = picking_pool.action_invoice_create(cr, uid, active_ids,
|
||||
journal_id = onshipdata_obj['journal_id'],
|
||||
group = onshipdata_obj['group'],
|
||||
type = None,
|
||||
context=context)
|
||||
invoice_ids += res.values()
|
||||
if not invoice_ids:
|
||||
raise osv.except_osv(_('Error'), _('No invoice were created'))
|
||||
|
||||
return {
|
||||
'domain': "[('id','in', ["+','.join(map(str,invoice_ids))+"])]",
|
||||
'name' : _('Invoices'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'account.invoice',
|
||||
'context': context,
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
raise osv.except_osv(_('Error'), _('No Invoices were created'))
|
||||
action_model = False
|
||||
action = {}
|
||||
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.get(action_model)
|
||||
action = action_pool.read(cr, uid, action_id, context=context)
|
||||
action['domain'] = "[('id','in', ["+','.join(map(str,invoice_ids))+"])]"
|
||||
return action
|
||||
|
||||
stock_invoice_onshipping()
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@
|
|||
"access_stock_location_path_manager","stock location path manager","model_stock_location_path","stock.group_stock_manager",1,1,1,1
|
||||
"access_stock_location_path_partner_manager","stock.location.path partner manager","model_stock_location_path","product.group_product_manager",1,1,1,1
|
||||
"access_stock_location_path_stock_user","stock.location.path stock user","model_stock_location_path","stock.group_stock_user",1,1,1,1
|
||||
"access_stock_location_path","stock.location.path","model_stock_location_path","base.group_sale_salesman",1,0,0,0
|
||||
"access_product_pulled_flow","product.pulled.flow","model_product_pulled_flow","base.group_sale_salesman",1,0,0,0
|
||||
|
|
|
Loading…
Reference in New Issue