[FIX] stock: invoice on delivery can be done on picking that aren't linked to a sale order/procurement. It fixes a bug in anlgo saxon yml test also
bzr revid: qdp-launchpad@openerp.com-20130909091056-40uvicvymia2yui2
This commit is contained in:
parent
f5ad729ab5
commit
6c9490d11c
|
@ -192,7 +192,7 @@
|
||||||
- company_id: base.main_company
|
- company_id: base.main_company
|
||||||
location_id: stock.stock_location_stock
|
location_id: stock.stock_location_stock
|
||||||
product_id: product.product_product_3
|
product_id: product.product_product_3
|
||||||
product_qty: 1.0
|
product_uom_qty: 1.0
|
||||||
product_uom: product.product_uom_unit
|
product_uom: product.product_uom_unit
|
||||||
location_dest_id: stock.stock_location_customers
|
location_dest_id: stock.stock_location_customers
|
||||||
invoice_state: 2binvoiced
|
invoice_state: 2binvoiced
|
||||||
|
@ -235,9 +235,7 @@
|
||||||
!python {model: stock.invoice.onshipping}: |
|
!python {model: stock.invoice.onshipping}: |
|
||||||
wiz_id = self.create(cr, uid, {'invoice_date': '2013-03-04', 'journal_id': ref('account.sales_journal')},
|
wiz_id = self.create(cr, uid, {'invoice_date': '2013-03-04', 'journal_id': ref('account.sales_journal')},
|
||||||
{'active_ids': [ref("stock_picking_out001")], "active_model": "stock.picking"})
|
{'active_ids': [ref("stock_picking_out001")], "active_model": "stock.picking"})
|
||||||
self.create_invoice(cr, uid, [wiz_id], {"lang": "en_US",
|
self.create_invoice(cr, uid, [wiz_id], {"active_ids": [ref("stock_picking_out001")], "active_id": ref("stock_picking_out001")})
|
||||||
"search_default_available": 1, "tz": False, "active_model": "stock.picking",
|
|
||||||
"contact_display": "partner", "active_ids": [ref("stock_picking_out001")], "active_id": ref("stock_picking_out001")})
|
|
||||||
-
|
-
|
||||||
I check that the customer invoice is created successfully.
|
I check that the customer invoice is created successfully.
|
||||||
-
|
-
|
||||||
|
|
|
@ -133,7 +133,7 @@ class stock_picking(osv.osv):
|
||||||
for picking in self.browse(cr, uid, ids, context=context):
|
for picking in self.browse(cr, uid, ids, context=context):
|
||||||
key = group and picking.id or True
|
key = group and picking.id or True
|
||||||
for move in picking.move_lines:
|
for move in picking.move_lines:
|
||||||
if move.procurement_id and (move.procurement_id.invoice_state=='2binvoiced'):
|
if move.procurement_id and (move.procurement_id.invoice_state == '2binvoiced') or move.invoice_state == '2binvoiced':
|
||||||
if (move.state <> 'cancel') and not move.scrapped:
|
if (move.state <> 'cancel') and not move.scrapped:
|
||||||
todo.setdefault(key, [])
|
todo.setdefault(key, [])
|
||||||
todo[key].append(move)
|
todo[key].append(move)
|
||||||
|
@ -146,12 +146,26 @@ class stock_picking(osv.osv):
|
||||||
invoice_obj = self.pool.get('account.invoice')
|
invoice_obj = self.pool.get('account.invoice')
|
||||||
invoices = {}
|
invoices = {}
|
||||||
for move in moves:
|
for move in moves:
|
||||||
sale_line = move.procurement_id.sale_line_id
|
company = move.company_id
|
||||||
sale = sale_line.order_id
|
account_analytic_id = False
|
||||||
partner = sale.partner_invoice_id
|
if move.procurement_id:
|
||||||
|
sale_line = move.procurement_id.sale_line_id
|
||||||
currency_id = sale.pricelist_id.currency_id.id
|
sale = sale_line.order_id
|
||||||
key = (partner.id, currency_id, sale.company_id.id, sale.user_id and sale.user_id.id or False)
|
user_id = self.user_id.id
|
||||||
|
partner = sale.partner_invoice_id
|
||||||
|
currency_id = sale.pricelist_id.currency_id.id
|
||||||
|
origin = sale.name
|
||||||
|
account_analytic_id = sale.project_id and sale.project_id.id or False
|
||||||
|
unit_price = sale_line.price_unit
|
||||||
|
discount = sale_line.discount
|
||||||
|
else:
|
||||||
|
partner = move.picking_id.partner_id
|
||||||
|
currency_id = company.currency_id.id
|
||||||
|
user_id = uid
|
||||||
|
origin = move.picking_id.name
|
||||||
|
unit_price = move.product_id.list_price #TODO: use price_get
|
||||||
|
discount = 0
|
||||||
|
key = (partner.id, currency_id, company.id, user_id)
|
||||||
|
|
||||||
if key not in invoices:
|
if key not in invoices:
|
||||||
# Get account and payment terms
|
# Get account and payment terms
|
||||||
|
@ -163,16 +177,16 @@ class stock_picking(osv.osv):
|
||||||
payment_term = partner.property_supplier_payment_term.id or False
|
payment_term = partner.property_supplier_payment_term.id or False
|
||||||
|
|
||||||
invoice_id = invoice_obj.create(cr, uid, {
|
invoice_id = invoice_obj.create(cr, uid, {
|
||||||
'origin': sale.name,
|
'origin': origin,
|
||||||
'date_invoice': context.get('date_inv', False),
|
'date_invoice': context.get('date_inv', False),
|
||||||
'user_id': sale.user_id and sale.user_id.id or False,
|
'user_id': user_id,
|
||||||
'partner_id': partner.id,
|
'partner_id': partner.id,
|
||||||
'account_id': account_id,
|
'account_id': account_id,
|
||||||
'payment_term': payment_term,
|
'payment_term': payment_term,
|
||||||
'type': inv_type,
|
'type': inv_type,
|
||||||
'fiscal_position': partner.property_account_position.id,
|
'fiscal_position': partner.property_account_position.id,
|
||||||
'company_id': sale.company_id.id,
|
'company_id': company.id,
|
||||||
'currency_id': sale.pricelist_id.currency_id.id,
|
'currency_id': currency_id,
|
||||||
'journal_id': journal_id,
|
'journal_id': journal_id,
|
||||||
}, context=context)
|
}, context=context)
|
||||||
invoices[key] = invoice_id
|
invoices[key] = invoice_id
|
||||||
|
@ -206,22 +220,23 @@ class stock_picking(osv.osv):
|
||||||
'product_id': move.product_id.id,
|
'product_id': move.product_id.id,
|
||||||
'uos_id': uos_id,
|
'uos_id': uos_id,
|
||||||
'quantity': quantity,
|
'quantity': quantity,
|
||||||
'price_unit': sale_line.price_unit,
|
'price_unit': unit_price,
|
||||||
'discount': sale_line.discount,
|
'discount': discount,
|
||||||
'invoice_line_tax_id': [(6, 0, [x.id for x in sale_line.tax_id])],
|
#'invoice_line_tax_id': [(6, 0, [x.id for x in sale_line.tax_id])], TODO add me back
|
||||||
'account_analytic_id': sale.project_id and sale.project_id.id or False,
|
'account_analytic_id': account_analytic_id,
|
||||||
}, context=context)
|
}, context=context)
|
||||||
|
|
||||||
self.pool.get('sale.order.line').write(cr, uid, [sale_line.id], {
|
if move.procurement_id:
|
||||||
'invoice_lines': [(4, invoice_line_id)]
|
self.pool.get('sale.order.line').write(cr, uid, [sale_line.id], {
|
||||||
}, context=context)
|
'invoice_lines': [(4, invoice_line_id)]
|
||||||
self.pool.get('sale.order').write(cr, uid, [sale.id], {
|
}, context=context)
|
||||||
'invoice_ids': [(4, invoices[key])],
|
self.pool.get('sale.order').write(cr, uid, [sale.id], {
|
||||||
})
|
'invoice_ids': [(4, invoices[key])],
|
||||||
|
})
|
||||||
|
|
||||||
self.pool.get('procurement.order').write(cr, uid, [move.procurement_id.id], {
|
self.pool.get('procurement.order').write(cr, uid, [move.procurement_id.id], {
|
||||||
'invoice_state': 'invoiced',
|
'invoice_state': 'invoiced',
|
||||||
}, context=context)
|
}, context=context)
|
||||||
|
|
||||||
invoice_obj.button_compute(cr, uid, invoices.values(), context=context, set_total=(inv_type in ('in_invoice', 'in_refund')))
|
invoice_obj.button_compute(cr, uid, invoices.values(), context=context, set_total=(inv_type in ('in_invoice', 'in_refund')))
|
||||||
return invoices.values()
|
return invoices.values()
|
||||||
|
|
|
@ -71,7 +71,6 @@ class stock_invoice_onshipping(osv.osv_memory):
|
||||||
def open_invoice(self, cr, uid, ids, context=None):
|
def open_invoice(self, cr, uid, ids, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
print 'Create Invoice', context
|
|
||||||
invoice_ids = self.create_invoice(cr, uid, ids, context=context)
|
invoice_ids = self.create_invoice(cr, uid, ids, context=context)
|
||||||
if not invoice_ids:
|
if not invoice_ids:
|
||||||
raise osv.except_osv(_('Error!'), _('No invoice created!'))
|
raise osv.except_osv(_('Error!'), _('No invoice created!'))
|
||||||
|
@ -97,7 +96,6 @@ class stock_invoice_onshipping(osv.osv_memory):
|
||||||
|
|
||||||
def create_invoice(self, cr, uid, ids, context=None):
|
def create_invoice(self, cr, uid, ids, context=None):
|
||||||
context = context or {}
|
context = context or {}
|
||||||
|
|
||||||
picking_pool = self.pool.get('stock.picking')
|
picking_pool = self.pool.get('stock.picking')
|
||||||
onshipdata_obj = self.read(cr, uid, ids, ['journal_id', 'group', 'invoice_date', 'inv_type'])
|
onshipdata_obj = self.read(cr, uid, ids, ['journal_id', 'group', 'invoice_date', 'inv_type'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue