[ADD] account_asset: Added a boolean field to skip the draft state when asset is created from invoice and based on that field confirm the asset.
bzr revid: uco@tinyerp.com-20110517114057-hz5wfbqfikw7y1hz
This commit is contained in:
parent
a2ffcb5888
commit
c501ebd60b
|
@ -37,6 +37,7 @@ class account_asset_category(osv.osv):
|
|||
'account_expense_depreciation_id': fields.many2one('account.account', 'Depr. Expense Account', required=True),
|
||||
'journal_id': fields.many2one('account.journal', 'Journal', required=True),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
'skip_draft_state': fields.boolean('Skip Draft State', help="Skips draft state for asset when created by invoice."),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
|
|
@ -26,20 +26,28 @@ class account_invoice(osv.osv):
|
|||
_inherit = 'account.invoice'
|
||||
def line_get_convert(self, cr, uid, x, part, date, context={}):
|
||||
res = super(account_invoice, self).line_get_convert(cr, uid, x, part, date, context)
|
||||
res['asset_id'] = x.get('asset_id', False)
|
||||
res['asset_category_id'] = x.get('asset_category_id', False)
|
||||
return res
|
||||
account_invoice()
|
||||
|
||||
class account_invoice_line(osv.osv):
|
||||
_inherit = 'account.invoice.line'
|
||||
_columns = {
|
||||
'asset_id': fields.many2one('account.asset.asset', 'Asset'),
|
||||
'asset_category_id': fields.many2one('account.asset.category', 'Asset Category'),
|
||||
}
|
||||
def move_line_get_item(self, cr, uid, line, context={}):
|
||||
res = super(account_invoice_line, self).move_line_get_item(cr, uid, line, context)
|
||||
res['asset_id'] = line.asset_id.id or False
|
||||
if line.asset_id.id and (line.asset_id.state=='draft'):
|
||||
self.pool.get('account.asset.asset').validate(cr, uid, [line.asset_id.id], context)
|
||||
res['asset_category_id'] = line.asset_category_id.id or False
|
||||
asset_obj = self.pool.get('account.asset.asset')
|
||||
if line.asset_category_id.id:
|
||||
vals = {
|
||||
'name': line.name + ": " + (line.product_id and line.product_id.name),
|
||||
'category_id': line.asset_category_id.id,
|
||||
'purchase_value': line.price_subtotal
|
||||
}
|
||||
asset_id = asset_obj.create(cr, uid, vals, context=context)
|
||||
if line.asset_category_id.skip_draft_state:
|
||||
asset_obj.validate(cr, uid, [asset_id], context=context)
|
||||
return res
|
||||
account_invoice_line()
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="invoice_line_tax_id" position="before">
|
||||
<field name="asset_id" context="name=name"/>
|
||||
<field name="asset_category_id" context="name=name"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
<field name="account_asset_id"/>
|
||||
<field name="account_depreciation_id"/>
|
||||
<field name="account_expense_depreciation_id"/>
|
||||
<field name="skip_draft_state"/>
|
||||
<group col="4" colspan="4" groups="analytic.group_analytic_accounting">
|
||||
<separator string="Analytic information" colspan="4" />
|
||||
<newline/>
|
||||
|
|
Loading…
Reference in New Issue