created new wizard for duplicate account chart
bzr revid: hmo@tinyerp.com-20080821071104-wuwrztxw6j4cpujp
This commit is contained in:
parent
a3e764fba5
commit
a67f0926f8
|
@ -346,7 +346,7 @@ class account_account(osv.osv):
|
|||
res.append((record['id'],name ))
|
||||
return res
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context={}):
|
||||
def copy(self, cr, uid, id, default={}, context={}):
|
||||
account = self.browse(cr, uid, id, context=context)
|
||||
new_child_ids = []
|
||||
default['parent_id'] = False
|
||||
|
@ -1781,5 +1781,59 @@ class account_chart_template(osv.osv):
|
|||
|
||||
account_chart_template()
|
||||
|
||||
class wizard_account_chart_duplicate(osv.osv_memory):
|
||||
"""
|
||||
Create a new account chart for a new company.
|
||||
Wizards ask:
|
||||
* an accuont chart (parent_id,=,False)
|
||||
* a company
|
||||
Then, the wizard:
|
||||
* duplicates all accounts and assign to the right company
|
||||
* duplicates all taxes, changing account assignations
|
||||
* duplicate all accounting properties and assign correctly
|
||||
"""
|
||||
_name = 'wizard.account.chart.duplicate'
|
||||
_columns = {
|
||||
'name':fields.char('Name',size=64),
|
||||
'account_id':fields.many2one('account.account','Account Chart',required=True,domain=[('parent_id','=',False)]),
|
||||
'company_id':fields.many2one('res.company','Company',required=True),
|
||||
|
||||
}
|
||||
|
||||
def action_create(self, cr, uid,ids, context=None):
|
||||
res=self.read(cr,uid,ids)[0]
|
||||
if res.get('account_id',False) and res.get('company_id',False):
|
||||
account_obj=self.pool.get('account.account')
|
||||
account_tax_obj=self.pool.get('account.tax')
|
||||
property_obj=self.pool.get('ir.property')
|
||||
# duplicate all accounts
|
||||
account_obj.copy(cr,uid,res['account_id'],default={'company_id':res['company_id']})
|
||||
# duplicate all taxes
|
||||
tax_ids=account_tax_obj.search(cr,uid,[])
|
||||
for tax in account_tax_obj.browse(cr,uid,tax_ids):
|
||||
val={'company_id':res['company_id']}
|
||||
if tax.account_collected_id:
|
||||
new_invoice_account_ids=account_obj.search(cr,uid,[('name','=',tax.account_collected_id.name),('company_id','=',res['company_id'])])
|
||||
val['account_collected_id']=len(new_invoice_account_ids) and new_invoice_account_ids[0] or False
|
||||
if tax.account_paid_id:
|
||||
new_refund_account_ids=account_obj.search(cr,uid,[('name','=',tax.account_paid_id.name),('company_id','=',res['company_id'])])
|
||||
val['account_paid_id']=len(new_refund_account_ids) and new_refund_account_ids[0] or False
|
||||
account_tax_obj.copy(cr,uid,tax.id,default=val)
|
||||
# duplicate all accouting properties
|
||||
property_ids=property_obj.search(cr,uid,[('value','=like','account.account,%')])
|
||||
for property in property_obj.browse(cr,uid,property_ids):
|
||||
account=account_obj.browse(cr,uid,property.value[1])
|
||||
if account:
|
||||
new_account_ids=account_obj.search(cr,uid,[('name','=',account.name),('company_id','=',res['company_id'])])
|
||||
if len(new_account_ids):
|
||||
property_obj.copy(cr,uid,property.id,default={
|
||||
'value':'account.account,'+str(new_account_ids[0]),
|
||||
'company_id':res['company_id']
|
||||
})
|
||||
|
||||
return {'type':'ir.actions.act_window_close'}
|
||||
|
||||
wizard_account_chart_duplicate()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -1581,5 +1581,33 @@
|
|||
|
||||
<menuitem action="action_account_tax_template_form" id="menu_action_account_tax_template_form" parent="account_account_template_menu"/>
|
||||
|
||||
<!-- wizard account duplicate chart -->
|
||||
<record id="view_wizard_account_duplicate_chart" model="ir.ui.view">
|
||||
<field name="name">wizard.account.chart.duplicate.form</field>
|
||||
<field name="model">wizard.account.chart.duplicate</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Duplicate Account Chart">
|
||||
<field name="account_id"/>
|
||||
<field name="company_id"/>
|
||||
<newline/>
|
||||
<group colspan="4">
|
||||
<button icon="gtk-cancel" special="cancel" type="object" string="Cancel"/>
|
||||
<button icon="gtk-ok" name="action_create" string="Create" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_wizard_account_duplicate_chart_form" model="ir.actions.act_window">
|
||||
<field name="name">Duplicate Account Chart</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">wizard.account.chart.duplicate</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
<menuitem action="action_wizard_account_duplicate_chart_form" id="menu_action_wizard_account_duplicate_chart_form" parent="account_account_menu"/>
|
||||
|
||||
</data>
|
||||
</terp>
|
||||
|
|
|
@ -1216,7 +1216,7 @@ class stock_picking_move_wizard(osv.osv_memory):
|
|||
_columns={
|
||||
'name':fields.char('Name',size=64,invisible=True),
|
||||
#'move_lines': fields.one2many('stock.move', 'picking_id', 'Move lines',readonly=True),
|
||||
'move_ids': fields.many2many('stock.move', 'picking_move_wizard_rel', 'picking_move_wizard_id', 'move_id', 'Move lines'),
|
||||
'move_ids': fields.many2many('stock.move', 'picking_move_wizard_rel', 'picking_move_wizard_id', 'move_id', 'Move lines',required=True),
|
||||
'address_id' : fields.many2one('res.partner.address', 'Dest. Address',invisible=True),
|
||||
'picking_id': fields.many2one('stock.picking', 'Packing list', select=True,invisible=True),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue