[EMRGE] journal_id on purchases
bzr revid: fp@tinyerp.com-20121102081326-q445izc6tje7axb1
This commit is contained in:
commit
062de3f041
|
@ -138,6 +138,17 @@ class purchase_order(osv.osv):
|
|||
res[purchase.id] = invoiced
|
||||
return res
|
||||
|
||||
def _get_journal(self, cr, uid, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
company_id = context.get('company_id', user.company_id.id)
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
res = journal_obj.search(cr, uid, [('type', '=', 'purchase'),
|
||||
('company_id', '=', company_id)],
|
||||
limit=1)
|
||||
return res and res[0] or False
|
||||
|
||||
STATE_SELECTION = [
|
||||
('draft', 'Draft PO'),
|
||||
('sent', 'RFQ Sent'),
|
||||
|
@ -204,6 +215,7 @@ class purchase_order(osv.osv):
|
|||
'product_id': fields.related('order_line','product_id', type='many2one', relation='product.product', string='Product'),
|
||||
'create_uid': fields.many2one('res.users', 'Responsible'),
|
||||
'company_id': fields.many2one('res.company','Company',required=True,select=1),
|
||||
'journal_id': fields.many2one('account.journal', 'Journal'),
|
||||
}
|
||||
_defaults = {
|
||||
'date_order': fields.date.context_today,
|
||||
|
@ -214,6 +226,7 @@ class purchase_order(osv.osv):
|
|||
'invoiced': 0,
|
||||
'pricelist_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').browse(cr, uid, context['partner_id']).property_product_pricelist_purchase.id,
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'purchase.order', context=c),
|
||||
'journal_id': _get_journal,
|
||||
}
|
||||
_sql_constraints = [
|
||||
('name_uniq', 'unique(name, company_id)', 'Order Reference must be unique per Company!'),
|
||||
|
|
|
@ -226,6 +226,7 @@
|
|||
<field name="partner_ref"/>
|
||||
<field domain="[('type','=','purchase')]" name="pricelist_id" groups="product.group_purchase_pricelist" on_change="onchange_pricelist(pricelist_id, context)"/>
|
||||
<field name="currency_id" invisible='1'/>
|
||||
<field name="journal_id" invisible='1'/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="date_order"/>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<field name="inherit_id" ref="purchase.purchase_order_line_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="account_analytic_id" position="replace">
|
||||
<field name="analytics_id" domain="[('plan_id','<>',False)]"/>
|
||||
<field name="analytics_id" context="{'journal_id':parent.journal_id}" domain="[('plan_id','<>',False)]"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -19,7 +19,7 @@
|
|||
<field name="inherit_id" ref="purchase.purchase_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="account_analytic_id" position="replace">
|
||||
<field name="analytics_id" domain="[('plan_id','<>',False)]"/>
|
||||
<field name="analytics_id" context="{'journal_id':parent.journal_id}" domain="[('plan_id','<>',False)]"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
|
Loading…
Reference in New Issue