diff --git a/addons/account/account.py b/addons/account/account.py
index 8e0b0d1abd2..99e3bb9ee68 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -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:
diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml
index 3e1c67e4fd9..19937c9e40b 100644
--- a/addons/account/account_view.xml
+++ b/addons/account/account_view.xml
@@ -1581,5 +1581,33 @@
+
+
+ wizard.account.chart.duplicate.form
+ wizard.account.chart.duplicate
+ form
+
+
+
+
+
+
+ Duplicate Account Chart
+ ir.actions.act_window
+ wizard.account.chart.duplicate
+ form
+ form
+ new
+
+
+
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 0ae82a7876b..224420d2e8d 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -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),
}