[MERGE] asset category on invoice line to create asset + skip draft state
authorQuentin (OpenERP) <qdp-launchpad@openerp.com>
Tue, 24 May 2011 15:52:19 +0000 (17:52 +0200)
committerQuentin (OpenERP) <qdp-launchpad@openerp.com>
Tue, 24 May 2011 15:52:19 +0000 (17:52 +0200)
bzr revid: qdp-launchpad@openerp.com-20110524155219-jziowms0j98tjvap

addons/account_asset/account_asset.py
addons/account_asset/account_asset_invoice.py
addons/account_asset/account_asset_invoice_view.xml
addons/account_asset/account_asset_view.xml

index a801d48..f5ef40c 100644 (file)
@@ -43,6 +43,7 @@ class account_asset_category(osv.osv):
         'method_progress_factor': fields.float('Progressif Factor'),
         'method_time': fields.selection([('delay','Delay'),('end','Ending Period')], 'Time Method', required=True),
         'prorata':fields.boolean('Prorata Temporis', help='Indicates that the accounting entries for this asset have to be done from the purchase date instead of the first January'),
+        'open_asset': fields.boolean('Skip Draft State', help="Check this if you want to automatically confirm the assets of this category when created by invoice."),
     }
 
     _defaults = {
index 1bc9fbc..f130bdc 100755 (executable)
@@ -33,13 +33,20 @@ 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={}):
+        asset_obj = self.pool.get('account.asset.asset')
         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)
+        if line.asset_category_id:
+            vals = {
+                'name': line.product_id and (line.name + ": " + line.product_id.name) or line.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.open_asset:
+                asset_obj.validate(cr, uid, [asset_id], context=context)
         return res
 account_invoice_line()
 
index 394d173..f694ce4 100755 (executable)
@@ -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>
index 2acdd64..39e2a7f 100644 (file)
                     <field name="method_delay"/>
                     <field name="method_period" attrs="{'invisible':[('method_time','=','end')]}"/>                
                 </group>
-                <group colspan="2" col="3">
-                    <separator string="Depreciation Method" colspan="4" />
+                <group colspan="2" col="2">
+                    <separator string="Depreciation Method" colspan="2" />
                     <field name="method"/>
-                    <newline/>
                     <field name="method_progress_factor" attrs="{'invisible':[('method','=','linear')]}"/>
-                    <newline/>
-                    <field name="prorata" colspan="1"/>
+                    <field name="prorata"/>
+                    <field name="open_asset"/>
                 </group>
                <group col="4" colspan="4" groups="analytic.group_analytic_accounting">
                    <separator string="Analytic information" colspan="4" />