[IMP] sale: force the company when creating an invoice from the SO, using context['force_company']
bzr revid: qdp-launchpad@openerp.com-20110707155920-25i3yzptikuadzj8
This commit is contained in:
parent
b4d3c937ad
commit
9f01872204
|
@ -25,6 +25,7 @@ import time
|
|||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
import tools
|
||||
import decimal_precision as dp
|
||||
import netsvc
|
||||
|
||||
|
@ -474,16 +475,21 @@ class sale_order(osv.osv):
|
|||
# last day of the last month as invoice date
|
||||
if date_inv:
|
||||
context['date_inv'] = date_inv
|
||||
for o in self.browse(cr, uid, ids, context=context):
|
||||
lines = []
|
||||
for line in o.order_line:
|
||||
if line.invoiced:
|
||||
continue
|
||||
elif (line.state in states):
|
||||
lines.append(line.id)
|
||||
created_lines = obj_sale_order_line.invoice_line_create(cr, uid, lines)
|
||||
if created_lines:
|
||||
invoices.setdefault(o.partner_id.id, []).append((o, created_lines))
|
||||
set_company = tools.get_and_sort_by_field(cr, uid, obj=self, ids=ids, field='company_id', context=context)
|
||||
for company_id, so_ids in set_company.items():
|
||||
ctx = context.copy()
|
||||
ctx.update({'force_company': company_id})
|
||||
print "Boom invoice", company_id, so_ids
|
||||
for o in self.browse(cr, uid, ids, context=ctx):
|
||||
lines = []
|
||||
for line in o.order_line:
|
||||
if line.invoiced:
|
||||
continue
|
||||
elif (line.state in states):
|
||||
lines.append(line.id)
|
||||
created_lines = obj_sale_order_line.invoice_line_create(cr, uid, lines, context=context)
|
||||
if created_lines:
|
||||
invoices.setdefault(o.partner_id.id, []).append((o, created_lines))
|
||||
if not invoices:
|
||||
for o in self.browse(cr, uid, ids, context=context):
|
||||
for i in o.invoice_ids:
|
||||
|
@ -914,50 +920,55 @@ class sale_order_line(osv.osv):
|
|||
|
||||
create_ids = []
|
||||
sales = {}
|
||||
for line in self.browse(cr, uid, ids, context=context):
|
||||
if not line.invoiced:
|
||||
if line.product_id:
|
||||
a = line.product_id.product_tmpl_id.property_account_income.id
|
||||
if not a:
|
||||
a = line.product_id.categ_id.property_account_income_categ.id
|
||||
set_company = tools.get_and_sort_by_field(cr, uid, obj=self, ids=ids, field='company_id', context=context)
|
||||
for company_id, sol_ids in set_company.items():
|
||||
ctx = context.copy()
|
||||
ctx.update({'force_company': company_id})
|
||||
print "Boom line", company_id, sol_ids
|
||||
for line in self.browse(cr, uid, sol_ids, context=ctx):
|
||||
if not line.invoiced:
|
||||
if line.product_id:
|
||||
a = line.product_id.product_tmpl_id.property_account_income.id
|
||||
if not a:
|
||||
a = line.product_id.categ_id.property_account_income_categ.id
|
||||
if not a:
|
||||
raise osv.except_osv(_('Error !'),
|
||||
_('There is no income account defined ' \
|
||||
'for this product: "%s" (id:%d)') % \
|
||||
(line.product_id.name, line.product_id.id,))
|
||||
else:
|
||||
prop = self.pool.get('ir.property').get(cr, uid,
|
||||
'property_account_income_categ', 'product.category',
|
||||
context=context)
|
||||
a = prop and prop.id or False
|
||||
uosqty = _get_line_qty(line)
|
||||
uos_id = _get_line_uom(line)
|
||||
pu = 0.0
|
||||
if uosqty:
|
||||
pu = round(line.price_unit * line.product_uom_qty / uosqty,
|
||||
self.pool.get('decimal.precision').precision_get(cr, uid, 'Sale Price'))
|
||||
fpos = line.order_id.fiscal_position or False
|
||||
a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, a)
|
||||
if not a:
|
||||
raise osv.except_osv(_('Error !'),
|
||||
_('There is no income account defined ' \
|
||||
'for this product: "%s" (id:%d)') % \
|
||||
(line.product_id.name, line.product_id.id,))
|
||||
else:
|
||||
prop = self.pool.get('ir.property').get(cr, uid,
|
||||
'property_account_income_categ', 'product.category',
|
||||
context=context)
|
||||
a = prop and prop.id or False
|
||||
uosqty = _get_line_qty(line)
|
||||
uos_id = _get_line_uom(line)
|
||||
pu = 0.0
|
||||
if uosqty:
|
||||
pu = round(line.price_unit * line.product_uom_qty / uosqty,
|
||||
self.pool.get('decimal.precision').precision_get(cr, uid, 'Sale Price'))
|
||||
fpos = line.order_id.fiscal_position or False
|
||||
a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, a)
|
||||
if not a:
|
||||
raise osv.except_osv(_('Error !'),
|
||||
_('There is no income category account defined in default Properties for Product Category or Fiscal Position is not defined !'))
|
||||
inv_id = self.pool.get('account.invoice.line').create(cr, uid, {
|
||||
'name': line.name,
|
||||
'origin': line.order_id.name,
|
||||
'account_id': a,
|
||||
'price_unit': pu,
|
||||
'quantity': uosqty,
|
||||
'discount': line.discount,
|
||||
'uos_id': uos_id,
|
||||
'product_id': line.product_id.id or False,
|
||||
'invoice_line_tax_id': [(6, 0, [x.id for x in line.tax_id])],
|
||||
'note': line.notes,
|
||||
'account_analytic_id': line.order_id.project_id and line.order_id.project_id.id or False,
|
||||
})
|
||||
cr.execute('insert into sale_order_line_invoice_rel (order_line_id,invoice_id) values (%s,%s)', (line.id, inv_id))
|
||||
self.write(cr, uid, [line.id], {'invoiced': True})
|
||||
sales[line.order_id.id] = True
|
||||
create_ids.append(inv_id)
|
||||
_('There is no income category account defined in default Properties for Product Category or Fiscal Position is not defined !'))
|
||||
inv_id = self.pool.get('account.invoice.line').create(cr, uid, {
|
||||
'name': line.name,
|
||||
'origin': line.order_id.name,
|
||||
'account_id': a,
|
||||
'price_unit': pu,
|
||||
'quantity': uosqty,
|
||||
'discount': line.discount,
|
||||
'uos_id': uos_id,
|
||||
'product_id': line.product_id.id or False,
|
||||
'invoice_line_tax_id': [(6, 0, [x.id for x in line.tax_id])],
|
||||
'note': line.notes,
|
||||
'account_analytic_id': line.order_id.project_id and line.order_id.project_id.id or False,
|
||||
})
|
||||
cr.execute('insert into sale_order_line_invoice_rel (order_line_id,invoice_id) values (%s,%s)', (line.id, inv_id))
|
||||
self.write(cr, uid, [line.id], {'invoiced': True})
|
||||
sales[line.order_id.id] = True
|
||||
create_ids.append(inv_id)
|
||||
# Trigger workflow events
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
for sid in sales.keys():
|
||||
|
|
Loading…
Reference in New Issue