[FIX] Added journal control per company for sale and purchase invoice creation
[ADD] Added company_id in pricelist [FIX] Removed duplicated company_id fields from stock bzr revid: fabian@fabian-openerp-20091202112006-ztnje8qdrgkg7nvl
This commit is contained in:
parent
ec0abc8968
commit
1578c2858d
|
@ -61,9 +61,15 @@ class account_invoice(osv.osv):
|
|||
if context is None:
|
||||
context = {}
|
||||
type_inv = context.get('type', 'out_invoice')
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
company_id = context.get('company_id', user.company_id.id)
|
||||
type2journal = {'out_invoice': 'sale', 'in_invoice': 'purchase', 'out_refund': 'sale', 'in_refund': 'purchase'}
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
res = journal_obj.search(cr, uid, [('type', '=', type2journal.get(type_inv, 'sale'))], limit=1)
|
||||
res = journal_obj.search(cr, uid, [('type', '=', type2journal.get(type_inv, 'sale')),
|
||||
('company_id', '=', company_id)],
|
||||
limit=1)
|
||||
print "XXX",context
|
||||
print "XXX",res
|
||||
if res:
|
||||
return res[0]
|
||||
else:
|
||||
|
|
|
@ -100,6 +100,7 @@ class product_pricelist(osv.osv):
|
|||
'type': fields.selection(_pricelist_type_get, 'Pricelist Type', required=True),
|
||||
'version_id': fields.one2many('product.pricelist.version', 'pricelist_id', 'Pricelist Versions'),
|
||||
'currency_id': fields.many2one('res.currency', 'Currency', required=True),
|
||||
'company_id': fields.many2one('res.company', 'Company'),
|
||||
}
|
||||
|
||||
def name_get(self, cr, uid, ids, context={}):
|
||||
|
@ -270,6 +271,7 @@ class product_pricelist_version(osv.osv):
|
|||
'price_version_id', 'Price List Items', required=True),
|
||||
'date_start': fields.date('Start Date', help="Starting date for this pricelist version to be valid."),
|
||||
'date_end': fields.date('End Date', help="Ending date for this pricelist version to be valid."),
|
||||
'company_id': fields.related('pricelist_id','company_id',type='many2one',relation='res.company',string='Company')
|
||||
}
|
||||
_defaults = {
|
||||
'active': lambda *a: 1,
|
||||
|
@ -366,6 +368,7 @@ class product_pricelist_item(osv.osv):
|
|||
digits=(16, int(config['price_accuracy']))),
|
||||
'price_max_margin': fields.float('Max. Price Margin',
|
||||
digits=(16, int(config['price_accuracy']))),
|
||||
'company_id': fields.related('price_version_id','company_id',type='many2one',relation='res.company',string='Company')
|
||||
}
|
||||
|
||||
_constraints = [
|
||||
|
|
|
@ -319,7 +319,10 @@ class purchase_order(osv.osv):
|
|||
il.append(self.inv_line_create(cr, uid, a, ol))
|
||||
|
||||
a = o.partner_id.property_account_payable.id
|
||||
journal_ids = journal_obj.search(cr, uid, [('type', '=','purchase')], limit=1)
|
||||
journal_ids = journal_obj.search(cr, uid, [('type', '=','purchase'),('company_id', '=', o.company_id.id)], limit=1)
|
||||
if not journal_ids:
|
||||
raise osv.except_osv(_('Error !'),
|
||||
_('There is no purchase journal defined for this company: "%s" (id:%d)') % (o.company_id.name, o.company_id.id))
|
||||
inv = {
|
||||
'name': o.partner_ref or o.name,
|
||||
'reference': "P%dPO%d" % (o.partner_id.id, o.id),
|
||||
|
|
|
@ -366,6 +366,11 @@ class sale_order(osv.osv):
|
|||
for preline in preinv.invoice_line:
|
||||
inv_line_id = self.pool.get('account.invoice.line').copy(cr, uid, preline.id, {'invoice_id': False, 'price_unit': -preline.price_unit})
|
||||
lines.append(inv_line_id)
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
journal_ids = journal_obj.search(cr, uid, [('type', '=','sale'),('company_id', '=', order.company_id.id)], limit=1)
|
||||
if not journal_ids:
|
||||
raise osv.except_osv(_('Error !'),
|
||||
_('There is no sale journal defined for this company: "%s" (id:%d)') % (order.company_id.name, order.company_id.id))
|
||||
inv = {
|
||||
'name': order.client_order_ref or order.name,
|
||||
'origin': order.name,
|
||||
|
@ -373,6 +378,7 @@ class sale_order(osv.osv):
|
|||
'reference': "P%dSO%d" % (order.partner_id.id, order.id),
|
||||
'account_id': a,
|
||||
'partner_id': order.partner_id.id,
|
||||
'journal_id': journal_ids[0],
|
||||
'address_invoice_id': order.partner_invoice_id.id,
|
||||
'address_contact_id': order.partner_order_id.id,
|
||||
'invoice_line': [(6, 0, lines)],
|
||||
|
@ -385,7 +391,7 @@ class sale_order(osv.osv):
|
|||
}
|
||||
inv_obj = self.pool.get('account.invoice')
|
||||
inv.update(self._inv_get(cr, uid, order))
|
||||
inv_id = inv_obj.create(cr, uid, inv)
|
||||
inv_id = inv_obj.create(cr, uid, inv, context)
|
||||
data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], pay_term, time.strftime('%Y-%m-%d'))
|
||||
if data.get('value', False):
|
||||
inv_obj.write(cr, uid, [inv_id], data['value'], context=context)
|
||||
|
|
|
@ -130,7 +130,6 @@ class stock_location(osv.osv):
|
|||
_columns = {
|
||||
'name': fields.char('Location Name', size=64, required=True, translate=True),
|
||||
'active': fields.boolean('Active'),
|
||||
'company_id': fields.many2one('res.company','Company',required=True),
|
||||
'usage': fields.selection([('supplier', 'Supplier Location'), ('view', 'View'), ('internal', 'Internal Location'), ('customer', 'Customer Location'), ('inventory', 'Inventory'), ('procurement', 'Procurement'), ('production', 'Production')], 'Location Type', required=True),
|
||||
'allocation_method': fields.selection([('fifo', 'FIFO'), ('lifo', 'LIFO'), ('nearest', 'Nearest')], 'Allocation Method', required=True),
|
||||
|
||||
|
@ -181,7 +180,6 @@ class stock_location(osv.osv):
|
|||
'posy': lambda *a: 0,
|
||||
'posz': lambda *a: 0,
|
||||
'icon': lambda *a: False,
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.location', c)
|
||||
}
|
||||
|
||||
def chained_location_get(self, cr, uid, location, partner=None, product=None, context={}):
|
||||
|
@ -1385,7 +1383,6 @@ class stock_inventory(osv.osv):
|
|||
'date_done': fields.datetime('Date done'),
|
||||
'inventory_line_id': fields.one2many('stock.inventory.line', 'inventory_id', 'Inventories', readonly=True, states={'draft': [('readonly', False)]}),
|
||||
'move_ids': fields.many2many('stock.move', 'stock_inventory_move_rel', 'inventory_id', 'move_id', 'Created Moves'),
|
||||
'company_id': fields.many2one('res.company','Company',required=True),
|
||||
'state': fields.selection( (('draft', 'Draft'), ('done', 'Done'), ('cancel','Cancelled')), 'State', readonly=True),
|
||||
'company_id': fields.many2one('res.company','Company',required=True),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue