[MERGE] Forward-port of latest 7.0 bugfixes, up to rev. 10005 revid:dle@openerp.com...
authorDenis Ledoux <dle@openerp.com>
Tue, 22 Apr 2014 16:20:28 +0000 (18:20 +0200)
committerDenis Ledoux <dle@openerp.com>
Tue, 22 Apr 2014 16:20:28 +0000 (18:20 +0200)
bzr revid: dle@openerp.com-20140422162028-2icoebrb5q4tg3t3

16 files changed:
1  2 
addons/account/account.py
addons/account/account_invoice_view.xml
addons/account/account_move_line.py
addons/account/project/project_view.xml
addons/account_analytic_plans/account_analytic_plans.py
addons/account_voucher/account_voucher.py
addons/crm/crm_lead_view.xml
addons/crm/crm_phonecall_view.xml
addons/mail/mail_mail_view.xml
addons/project_issue/project_issue_view.xml
addons/purchase/purchase_view.xml
addons/sale/sale_demo.xml
addons/sale/sale_view.xml
addons/sale_stock/sale_stock_demo.xml
addons/stock/stock.py
addons/stock/wizard/stock_location_product.py

@@@ -27,7 -27,7 +27,7 @@@ import tim
  
  import openerp
  from openerp import SUPERUSER_ID
 -from openerp import pooler, tools
 +from openerp import tools
  from openerp.osv import fields, osv, expression
  from openerp.tools.translate import _
  from openerp.tools.float_utils import float_round as round
@@@ -132,6 -132,7 +132,6 @@@ class account_payment_term_line(osv.osv
          (_check_percent, 'Percentages for Payment Term Line must be between 0 and 1, Example: 0.02 for 2%.', ['value_amount']),
      ]
  
 -account_payment_term_line()
  
  class account_account_type(osv.osv):
      _name = "account.account.type"
      }
      _order = "code"
  
 -account_account_type()
  
  def _code_get(self, cr, uid, context=None):
      acc_type_obj = self.pool.get('account.account.type')
  
  class account_tax(osv.osv):
      _name = 'account.tax'
 -account_tax()
  
  class account_account(osv.osv):
      _order = "parent_left"
          self._check_moves(cr, uid, ids, "unlink", context=context)
          return super(account_account, self).unlink(cr, uid, ids, context=context)
  
 -account_account()
  
  class account_journal(osv.osv):
      _name = "account.journal"
          'user_id': fields.many2one('res.users', 'User', help="The user responsible for this journal"),
          'groups_id': fields.many2many('res.groups', 'account_journal_group_rel', 'journal_id', 'group_id', 'Groups'),
          'currency': fields.many2one('res.currency', 'Currency', help='The currency used to enter statement'),
 -        'entry_posted': fields.boolean('Skip \'Draft\' State for Manual Entries', help='Check this box if you don\'t want new journal entries to pass through the \'draft\' state and instead goes directly to the \'posted state\' without any manual validation. \nNote that journal entries that are automatically created by the system are always skipping that state.'),
 +        'entry_posted': fields.boolean('Autopost Created Moves', help='Check this box to automatically post entries of this journal. Note that legally, some entries may be automatically posted when the source document is validated (Invoices), whatever the status of this field.'),
          'company_id': fields.many2one('res.company', 'Company', required=True, select=1, help="Company related to this journal"),
          'allow_date':fields.boolean('Check Date in Period', help= 'If set to True then do not accept the entry if the entry date is not into the period dates'),
  
          ids = self.search(cr, user, expression.AND([domain, args]), limit=limit, context=context)
          return self.name_get(cr, user, ids, context=context)
  
 -account_journal()
  
  class account_fiscalyear(osv.osv):
      _name = "account.fiscalyear"
          ids = self.search(cr, user, expression.AND([domain, args]), limit=limit, context=context)
          return self.name_get(cr, user, ids, context=context)
  
 -account_fiscalyear()
  
  class account_period(osv.osv):
      _name = "account.period"
              company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
              args.append(('company_id', '=', company_id))
          result = []
 -        #WARNING: in next version the default value for account_periof_prefer_normal will be True
 -        if context.get('account_period_prefer_normal'):
 +        if context.get('account_period_prefer_normal', True):
              # look for non-special periods first, and fallback to all if no result is found
              result = self.search(cr, uid, args + [('special', '=', False)], context=context)
          if not result:
              result = self.search(cr, uid, args, context=context)
          if not result:
 -            raise osv.except_osv(_('Error!'), _('There is no period defined for this date: %s.\nPlease create one.')%dt)
 +            model, action_id = self.pool['ir.model.data'].get_object_reference(cr, uid, 'account', 'action_account_fiscalyear')
 +            msg = _('There is no period defined for this date: %s.\nPlease, go to Configuration/Periods and configure a fiscal year.') % dt
 +            raise openerp.exceptions.RedirectWarning(msg, action_id, _('Go to the configuration panel'))
 +
          return result
  
      def action_draft(self, cr, uid, ids, *args):
              return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop)])
          return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('special', '=', False)])
  
 -account_period()
  
  class account_journal_period(osv.osv):
      _name = "account.journal.period"
      }
      _order = "period_id"
  
 -account_journal_period()
  
  class account_fiscalyear(osv.osv):
      _inherit = "account.fiscalyear"
          })
          return super(account_fiscalyear, self).copy(cr, uid, id, default=default, context=context)
  
 -account_fiscalyear()
  #----------------------------------------------------------
  # Entries
  #----------------------------------------------------------
@@@ -1164,7 -1171,7 +1164,7 @@@ class account_move(osv.osv)
              context = {}
          #put the company in context to find the good period
          ctx = context.copy()
 -        ctx.update({'company_id': company_id, 'account_period_prefer_normal': True})
 +        ctx.update({'company_id': company_id})
          return {
              'journal_id': journal_id,
              'date': date,
          return res
  
      def _get_period(self, cr, uid, context=None):
 -        ctx = dict(context or {}, account_period_prefer_normal=True)
 +        ctx = dict(context or {})
          period_ids = self.pool.get('account.period').find(cr, uid, context=ctx)
          return period_ids[0]
  
          valid_moves = [move.id for move in valid_moves]
          return len(valid_moves) > 0 and valid_moves or False
  
 -account_move()
  
  class account_move_reconcile(osv.osv):
      _name = "account.move.reconcile"
                  result.append((r.id,r.name))
          return result
  
 -account_move_reconcile()
  
  #----------------------------------------------------------
  # Tax
@@@ -1770,7 -1779,8 +1770,7 @@@ class account_tax_code(osv.osv)
          if context.get('period_id', False):
              period_id = context['period_id']
          else:
 -            ctx = dict(context, account_period_prefer_normal=True)
 -            period_id = self.pool.get('account.period').find(cr, uid, context=ctx)
 +            period_id = self.pool.get('account.period').find(cr, uid, context=context)
              if not period_id:
                  return dict.fromkeys(ids, 0.0)
              period_id = period_id[0]
      ]
      _order = 'code'
  
  
  def get_precision_tax():
      def change_digit_tax(cr):
 -        res = pooler.get_pool(cr.dbname).get('decimal.precision').precision_get(cr, SUPERUSER_ID, 'Account')
 +        res = openerp.registry(cr.dbname)['decimal.precision'].precision_get(cr, SUPERUSER_ID, 'Account')
          return (16, res+3)
      return change_digit_tax
  
@@@ -1888,7 -1899,7 +1888,7 @@@ class account_tax(osv.osv)
          'child_depend':fields.boolean('Tax on Children', help="Set if the tax computation is based on the computation of child taxes rather than on the total amount."),
          'python_compute':fields.text('Python Code'),
          'python_compute_inv':fields.text('Python Code (reverse)'),
 -        'python_applicable':fields.text('Python Code'),
 +        'python_applicable':fields.text('Applicable Code'),
  
          #
          # Fields used for the Tax declaration
  
          'ref_base_code_id': fields.many2one('account.tax.code', 'Refund Base Code', help="Use this code for the tax declaration."),
          'ref_tax_code_id': fields.many2one('account.tax.code', 'Refund Tax Code', help="Use this code for the tax declaration."),
 -        'ref_base_sign': fields.float('Base Code Sign', help="Usually 1 or -1.", digits_compute=get_precision_tax()),
 -        'ref_tax_sign': fields.float('Tax Code Sign', help="Usually 1 or -1.", digits_compute=get_precision_tax()),
 +        'ref_base_sign': fields.float('Refund Base Code Sign', help="Usually 1 or -1.", digits_compute=get_precision_tax()),
 +        'ref_tax_sign': fields.float('Refund Tax Code Sign', help="Usually 1 or -1.", digits_compute=get_precision_tax()),
          'include_base_amount': fields.boolean('Included in base amount', help="Indicates if the amount of tax must be included in the base amount for the computation of the next taxes"),
          'company_id': fields.many2one('res.company', 'Company', required=True),
          'description': fields.char('Tax Code'),
          return super(account_tax, self).write(cr, uid, ids, vals, context=context)
  
      def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
+         if context is None:
+             context = {}
          journal_pool = self.pool.get('account.journal')
  
-         if context and context.has_key('type'):
+         if context.get('type'):
              if context.get('type') in ('out_invoice','out_refund'):
                  args += [('type_tax_use','in',['sale','all'])]
              elif context.get('type') in ('in_invoice','in_refund'):
                  args += [('type_tax_use','in',['purchase','all'])]
  
-         if context and context.has_key('journal_id'):
+         if context.get('journal_id'):
              journal = journal_pool.browse(cr, uid, context.get('journal_id'))
              if journal.type in ('sale', 'purchase'):
                  args += [('type_tax_use','in',[journal.type,'all'])]
                  total += r['amount']
          return res
  
 -account_tax()
  
  # ---------------------------------------------------------
  # Account Entries Models
@@@ -2283,7 -2297,7 +2285,7 @@@ class account_model(osv.osv)
          move_date = datetime.strptime(move_date,"%Y-%m-%d")
          for model in self.browse(cr, uid, ids, context=context):
              ctx = context.copy()
 -            ctx.update({'company_id': model.company_id.id, 'account_period_prefer_normal': True})
 +            ctx.update({'company_id': model.company_id.id})
              period_ids = period_obj.find(cr, uid, dt=context.get('date', False), context=ctx)
              period_id = period_ids and period_ids[0] or False
              ctx.update({'journal_id': model.journal_id.id,'period_id': period_id})
  
          return {'value': {'company_id': company_id}}
  
 -account_model()
  
  class account_model_line(osv.osv):
      _name = "account.model.line"
          ('credit_debit1', 'CHECK (credit*debit=0)',  'Wrong credit or debit value in model, they must be positive!'),
          ('credit_debit2', 'CHECK (credit+debit>=0)', 'Wrong credit or debit value in model, they must be positive!'),
      ]
 -account_model_line()
  
  # ---------------------------------------------------------
  # Account Subscription
@@@ -2450,6 -2466,7 +2452,6 @@@ class account_subscription(osv.osv)
          self.write(cr, uid, ids, {'state':'running'})
          return True
  
 -account_subscription()
  
  class account_subscription_line(osv.osv):
      _name = "account.subscription.line"
  
      _rec_name = 'date'
  
 -account_subscription_line()
  
  #  ---------------------------------------------------------------
  #   Account Templates: Account, Tax, Tax Code and chart. + Wizard
  
  class account_tax_template(osv.osv):
      _name = 'account.tax.template'
 -account_tax_template()
  
  class account_account_template(osv.osv):
      _order = "code"
          obj_acc._parent_store_compute(cr)
          return acc_template_ref
  
 -account_account_template()
  
  class account_add_tmpl_wizard(osv.osv_memory):
      """Add one more account from the template.
      def action_cancel(self, cr, uid, ids, context=None):
          return { 'type': 'state', 'state': 'end' }
  
 -account_add_tmpl_wizard()
  
  class account_tax_code_template(osv.osv):
  
          (_check_recursion, 'Error!\nYou cannot create recursive Tax Codes.', ['parent_id'])
      ]
      _order = 'code,name'
 -account_tax_code_template()
  
  
  class account_chart_template(osv.osv):
          'parent_id': fields.many2one('account.chart.template', 'Parent Chart Template'),
          'code_digits': fields.integer('# of Digits', required=True, help="No. of Digits to use for account code"),
          'visible': fields.boolean('Can be Visible?', help="Set this to False if you don't want this template to be used actively in the wizard that generate Chart of Accounts from templates, this is useful when you want to generate accounts of this template only when loading its child template."),
 +        'currency_id': fields.many2one('res.currency', 'Currency'),
          'complete_tax_set': fields.boolean('Complete Set of Taxes', help='This boolean helps you to choose if you want to propose to the user to encode the sale and purchase rates or choose from list of taxes. This last choice assumes that the set of tax defined on this template is complete'),
          'account_root_id': fields.many2one('account.account.template', 'Root Account', domain=[('parent_id','=',False)]),
          'tax_code_root_id': fields.many2one('account.tax.code.template', 'Root Tax Code', domain=[('parent_id','=',False)]),
          'complete_tax_set': True,
      }
  
 -account_chart_template()
  
  class account_tax_template(osv.osv):
  
          'child_depend':fields.boolean('Tax on Children', help="Set if the tax computation is based on the computation of child taxes rather than on the total amount."),
          'python_compute':fields.text('Python Code'),
          'python_compute_inv':fields.text('Python Code (reverse)'),
 -        'python_applicable':fields.text('Python Code'),
 +        'python_applicable':fields.text('Applicable Code'),
  
          #
          # Fields used for the Tax declaration
  
          'ref_base_code_id': fields.many2one('account.tax.code.template', 'Refund Base Code', help="Use this code for the tax declaration."),
          'ref_tax_code_id': fields.many2one('account.tax.code.template', 'Refund Tax Code', help="Use this code for the tax declaration."),
 -        'ref_base_sign': fields.float('Base Code Sign', help="Usually 1 or -1."),
 -        'ref_tax_sign': fields.float('Tax Code Sign', help="Usually 1 or -1."),
 +        'ref_base_sign': fields.float('Refund Base Code Sign', help="Usually 1 or -1."),
 +        'ref_tax_sign': fields.float('Refund Tax Code Sign', help="Usually 1 or -1."),
          'include_base_amount': fields.boolean('Include in Base Amount', help="Set if the amount of tax must be included in the base amount before computing the next taxes."),
          'description': fields.char('Internal Name'),
          'type_tax_use': fields.selection([('sale','Sale'),('purchase','Purchase'),('all','All')], 'Tax Use In', required=True,),
          res.update({'tax_template_to_tax': tax_template_to_tax, 'account_dict': todo_dict})
          return res
  
 -account_tax_template()
  
  # Fiscal Position Templates
  
@@@ -2945,6 -2968,7 +2947,6 @@@ class account_fiscal_position_template(
                  })
          return True
  
 -account_fiscal_position_template()
  
  class account_fiscal_position_tax_template(osv.osv):
      _name = 'account.fiscal.position.tax.template'
          'tax_dest_id': fields.many2one('account.tax.template', 'Replacement Tax')
      }
  
 -account_fiscal_position_tax_template()
  
  class account_fiscal_position_account_template(osv.osv):
      _name = 'account.fiscal.position.account.template'
          'account_dest_id': fields.many2one('account.account.template', 'Account Destination', domain=[('type','<>','view')], required=True)
      }
  
 -account_fiscal_position_account_template()
  
  # ---------------------------------------------------------
  # Account generation from template wizards
@@@ -3023,10 -3049,16 +3025,10 @@@ class wizard_multi_charts_accounts(osv.
      def onchange_chart_template_id(self, cr, uid, ids, chart_template_id=False, context=None):
          res = {}
          tax_templ_obj = self.pool.get('account.tax.template')
          res['value'] = {'complete_tax_set': False, 'sale_tax': False, 'purchase_tax': False}
          if chart_template_id:
              data = self.pool.get('account.chart.template').browse(cr, uid, chart_template_id, context=context)
 -            #set currecy_id based on selected COA template using ir.vaalues else current users company's currency
 -            value_id = ir_values.search(cr, uid, [('model', '=', 'account.chart.template'), ('res_id', '=', chart_template_id)], limit=1, context=context)
 -            if value_id:
 -                currency_id = int(ir_values.browse(cr, uid, value_id[0], context=context).value)
 -            else:
 -                currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
 +            currency_id = data.currency_id and data.currency_id.id or self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
              res['value'].update({'complete_tax_set': data.complete_tax_set, 'currency_id': currency_id})
              if data.complete_tax_set:
              # default tax is given by the lowest sequence. For same sequence we will take the latest created as it will be the case for tax created while isntalling the generic chart of account
          res = super(wizard_multi_charts_accounts, self).default_get(cr, uid, fields, context=context)
          tax_templ_obj = self.pool.get('account.tax.template')
          account_chart_template = self.pool['account.chart.template']
 -        data_obj = self.pool.get('ir.model.data')
  
          if 'bank_accounts_id' in fields:
              res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'},{'acc_name': _('Bank'), 'account_type': 'bank'}]})
              #in order to set default chart which was last created set max of ids.
              chart_id = max(ids)
              if context.get("default_charts"):
 -                data_ids = data_obj.search(cr, uid, [('model', '=', 'account.chart.template'), ('module', '=', context.get("default_charts"))], limit=1, context=context)
 -                if data_ids:
 -                    chart_id = data_obj.browse(cr, uid, data_ids[0], context=context).res_id
 +                model_data = self.pool.get('ir.model.data').search_read(cr, uid, [('model','=','account.chart.template'),('module','=',context.get("default_charts"))], ['res_id'], context=context)
 +                if model_data:
 +                    chart_id = model_data[0]['res_id']
              chart = account_chart_template.browse(cr, uid, chart_id, context=context)
              chart_hierarchy_ids = self._get_chart_parent_ids(cr, uid, chart, context=context) 
              if 'chart_template_id' in fields:
          def _get_analytic_journal(journal_type):
              # Get the analytic journal
              data = False
 -            if journal_type in ('sale', 'sale_refund'):
 -                data = obj_data.get_object_reference(cr, uid, 'account', 'analytic_journal_sale')
 -            elif journal_type in ('purchase', 'purchase_refund'):
 -                pass
 -            elif journal_type == 'general':
 +            try:
 +                if journal_type in ('sale', 'sale_refund'):
 +                    data = obj_data.get_object_reference(cr, uid, 'account', 'analytic_journal_sale')
 +                elif journal_type in ('purchase', 'purchase_refund'):
 +                    data = obj_data.get_object_reference(cr, uid, 'account', 'exp')
 +                elif journal_type == 'general':
 +                    pass
 +            except ValueError:
                  pass
              return data and data[1] or False
  
                  try:
                      tmp2 = obj_data.get_object_reference(cr, uid, *ref)
                      if tmp2: 
 -                        self.pool.get(tmp2[0]).write(cr, uid, tmp2[1], {
 +                        self.pool[tmp2[0]].write(cr, uid, tmp2[1], {
                              'currency_id': obj_wizard.currency_id.id
                          })
                  except ValueError:
              current_num += 1
          return True
  
 -wizard_multi_charts_accounts()
  
  class account_bank_accounts_wizard(osv.osv_memory):
      _name='account.bank.accounts.wizard'
          'account_type': fields.selection([('cash','Cash'), ('check','Check'), ('bank','Bank')], 'Account Type', size=32),
      }
  
 -account_bank_accounts_wizard()
  
  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
              <field name="arch" type="xml">
                  <tree colors="blue:state == 'draft';black:state in ('proforma','proforma2','open');gray:state == 'cancel'" string="Invoice">
                      <field name="partner_id" groups="base.group_user"/>
 +                    <field name="commercial_partner_id" invisible="1"/>
                      <field name="date_invoice"/>
                      <field name="number"/>
                      <field name="reference" invisible="1"/>
                                on_change="onchange_partner_id(type,partner_id,date_invoice,payment_term, partner_bank_id,company_id)"
                                context="{'default_customer': 0, 'search_default_supplier': 1, 'default_supplier': 1}"
                                domain="[('supplier', '=', True)]"/>
 -                            <field name="fiscal_position" widget="selection"/>
 +                            <field name="fiscal_position" options="{'no_create': True}"/>
                              <field name="origin"/>
                              <field name="supplier_invoice_number"/>
                              <label for="reference_type"/>
                              <field domain="[('company_id', '=', company_id), ('type', '=', 'payable')]"
                                  name="account_id" groups="account.group_account_user"/>
                              <field name="journal_id" groups="account.group_account_user"
 -                                on_change="onchange_journal_id(journal_id, context)" widget="selection"/>
 +                                on_change="onchange_journal_id(journal_id, context)" options="{'no_create': True}"/>
                              <field name="currency_id" groups="base.group_multi_currency"/>
                              <field name="check_total" groups="account.group_supplier_inv_check_total"/>
                          </group>
                              <group>
                                  <group>
                                      <field domain="[('partner_id', '=', partner_id)]" name="partner_bank_id" on_change="onchange_partner_bank(partner_bank_id)"/>
 -                                    <field name="user_id"/>
 +                                    <field name="user_id" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'account.group_account_invoice']}"/>
                                      <field name="name" invisible="1"/>
 -                                    <field name="payment_term" widget="selection"/>
 +                                    <field name="payment_term" options="{'no_create': True}"/>
                                  </group>
                                  <group>
                                      <field name="move_id" groups="account.group_account_user"/>
                                      <field name="period_id" domain="[('state', '=', 'draft'), ('company_id', '=', company_id)]" groups="account.group_account_user"/>
 -                                    <field name="company_id" on_change="onchange_company_id(company_id,partner_id,type,invoice_line,currency_id)" widget="selection" groups="base.group_multi_company"/>
 +                                    <field name="company_id" on_change="onchange_company_id(company_id,partner_id,type,invoice_line,currency_id,context)" widget="selection" groups="base.group_multi_company"/>
                                  </group>
                              </group>
                          </page>
                          <group>
                              <field string="Customer" name="partner_id"
                                  on_change="onchange_partner_id(type,partner_id,date_invoice,payment_term, partner_bank_id,company_id)"
 -                                groups="base.group_user" context="{'search_default_customer':1, 'show_address': 1}"
 +                                context="{'search_default_customer':1, 'show_address': 1}"
                                  options='{"always_reload": True}'
                                  domain="[('customer', '=', True)]"/>
 -                            <field name="fiscal_position" widget="selection" />
 +                            <field name="fiscal_position" options="{'no_create': True}" />
                          </group>
                          <group>
                              <field name="date_invoice"/>
                              <field name="journal_id" groups="account.group_account_user"
 -                                on_change="onchange_journal_id(journal_id, context)" widget="selection"/>
 +                                on_change="onchange_journal_id(journal_id, context)" options="{'no_create': True}"/>
                              <field domain="[('company_id', '=', company_id),('type','=', 'receivable')]"
                                  name="account_id" groups="account.group_account_user"/>
  
                              <label for="currency_id" groups="base.group_multi_currency"/>
                              <div groups="base.group_multi_currency">
                                  <field name="currency_id" class="oe_inline"/>
 -                                <!-- note fp: I don't think we need this feature ?
                                  <button name="%(action_account_change_currency)d" type="action"
 -                                  icon="terp-stock_effects-object-colorize"
 +                                  class="oe_inline oe_link oe_edit_only"
 +                                  string="(change)"
                                    attrs="{'invisible':[('state','!=','draft')]}"
 -                                  groups="account.group_account_user"/> -->
 +                                  groups="account.group_account_user"/>
                              </div>
                          </group>
                      </group>
                          <page string="Other Info">
                              <group col="4">
                                  <group>
 -                                    <field name="company_id" on_change="onchange_company_id(company_id,partner_id,type,invoice_line,currency_id)" widget="selection" groups="base.group_multi_company"/>
 -                                    <field name="user_id" groups="base.group_user"/>
 +                                    <field name="company_id" on_change="onchange_company_id(company_id,partner_id,type,invoice_line,currency_id,context)" widget="selection" groups="base.group_multi_company"/>
 +                                    <field name="user_id" groups="base.group_user" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'account.group_account_invoice']}"/>
                                      <field domain="[('partner_id.ref_companies', 'in', [company_id])]" name="partner_bank_id"/>
                                      <field name="period_id" domain="[('state', '=', 'draft'), ('company_id', '=', company_id)]"
                                          groups="account.group_account_manager"
                      <filter name="invoices" string="Invoices" domain="[('state','not in',['draft','cancel'])]" help="Proforma/Open/Paid Invoices"/>
                      <filter name="unpaid" string="Unpaid" domain="[('state','=','open')]" help="Unpaid Invoices"/>
                      <separator/>
-                     <field name="partner_id" filter_domain="[('partner_id', 'child_of', self)]"/>
 -                    <filter domain="[('user_id','=',uid)]" help="My Invoices" icon="terp-personal"/>
+                     <field name="partner_id" operator="child_of"/>
                      <field name="user_id" string="Salesperson"/>
                      <field name="period_id" string="Period"/>
 +                    <separator/>
 +                    <filter domain="[('user_id','=',uid)]" help="My Invoices"/>
                      <group expand="0" string="Group By...">
 -                        <filter string="Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
 +                      <filter name="group_by_partner_id" string="Partner" domain="[]" context="{'group_by':'partner_id'}"/>
 +                      <filter name="commercial_partner_id" string="Commercial Partner" domain="[]" context="{'group_by':'commercial_partner_id'}"/>
                          <filter string="Responsible" icon="terp-personal" domain="[]"  context="{'group_by':'user_id'}"/>
                          <filter string="Journal" icon="terp-folder-orange" domain="[]" context="{'group_by':'journal_id'}"/>
                          <filter string="Status" icon="terp-stock_effects-object-colorize" domain="[]"  context="{'group_by':'state'}"/>
                          <filter string="Period" icon="terp-go-month" domain="[]" context="{'group_by':'period_id'}"/>
 -                        <filter string="Invoice Date" icon="terp-go-month" domain="[]"  context="{'group_by':'date_invoice'}"/>
 -                        <filter string="Due Date" icon="terp-go-month" domain="[]"  context="{'group_by':'date_due'}"/>
 +                        <filter string="Invoice Month" icon="terp-go-month" domain="[]"  context="{'group_by':'date_invoice'}"/>
 +                        <filter string="Due Month" icon="terp-go-month" domain="[]"  context="{'group_by':'date_due'}"/>
                      </group>
                 </search>
              </field>
          </record>
          <menuitem action="action_invoice_tree4" id="menu_action_invoice_tree4" parent="menu_finance_payables"/>
  
 -        <act_window context="{'search_default_partner_id':[active_id], 'default_partner_id': active_id}" id="act_res_partner_2_account_invoice_opened" name="Invoices" res_model="account.invoice" src_model="res.partner"/>
 -
          <act_window
             id="act_account_journal_2_account_invoice_opened"
             name="Unpaid Invoices"
@@@ -26,7 -26,7 +26,7 @@@ from operator import itemgette
  
  from lxml import etree
  
 -from openerp import netsvc
 +from openerp import workflow
  from openerp.osv import fields, osv, orm
  from openerp.tools.translate import _
  import openerp.addons.decimal_precision as dp
@@@ -515,7 -515,8 +515,7 @@@ class account_move_line(osv.osv)
          if context.get('period_id', False):
              return context['period_id']
          account_period_obj = self.pool.get('account.period')
 -        ctx = dict(context, account_period_prefer_normal=True)
 -        ids = account_period_obj.find(cr, uid, context=ctx)
 +        ids = account_period_obj.find(cr, uid, context=context)
          period_id = False
          if ids:
              period_id = ids[0]
              'line_id': map(lambda x: (4, x, False), ids),
              'line_partial_ids': map(lambda x: (3, x, False), ids)
          })
          # the id of the move.reconcile is written in the move.line (self) by the create method above
          # because of the way the line_id are defined: (4, x, False)
          for id in ids:
 -            wf_service.trg_trigger(uid, 'account.move.line', id, cr)
 +            workflow.trg_trigger(uid, 'account.move.line', id, cr)
  
          if lines and lines[0]:
              partner_id = lines[0].partner_id and lines[0].partner_id.id or False
          if context is None:
              context = {}
          period_pool = self.pool.get('account.period')
 -        ctx = dict(context, account_period_prefer_normal=True)
 -        pids = period_pool.find(cr, user, date, context=ctx)
 +        pids = period_pool.find(cr, user, date, context=context)
          if pids:
              res.update({
                  'period_id':pids[0]
          part_rec_ids = [rec['reconcile_partial_id'][0] for rec in part_recs]
          unlink_ids += rec_ids
          unlink_ids += part_rec_ids
+         all_moves = obj_move_line.search(cr, uid, ['|',('reconcile_id', 'in', unlink_ids),('reconcile_partial_id', 'in', unlink_ids)])
+         all_moves = list(set(all_moves) - set(move_ids))
          if unlink_ids:
              if opening_reconciliation:
                  obj_move_rec.write(cr, uid, unlink_ids, {'opening_reconciliation': False})
              obj_move_rec.unlink(cr, uid, unlink_ids)
+             if all_moves:
+                 obj_move_line.reconcile_partial(cr, uid, all_moves, 'auto',context=context)
          return True
  
      def unlink(self, cr, uid, ids, context=None, check=True):
                  bool(journal.currency),bool(journal.analytic_journal_id)))
          return result
  
 -account_move_line()
  
  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@@ -31,7 -31,7 +31,7 @@@
                  <search string="Analytic Account">
                      <field name="name" filter_domain="['|', ('name','ilike',self), ('code','ilike',self)]" string="Analytic Account"/>
                      <field name="date"/>
-                     <field name="partner_id" filter_domain="[('partner_id','child_of',self)]"/>
+                     <field name="partner_id" operator="child_of"/>
                      <field name="manager_id"/>
                      <field name="parent_id"/>
                      <field name="user_id"/>
@@@ -78,7 -78,6 +78,7 @@@
              <field name="name">Analytic Accounts</field>
              <field name="type">ir.actions.act_window</field>
              <field name="res_model">account.analytic.account</field>
 +            <field name="context">{}</field> <!-- repair invalid context by setting empty one -->
              <field name="view_type">form</field>
              <field name="view_mode">tree,form</field>
              <field name="view_id" ref="view_account_analytic_account_tree"/>
                              <field name="name"/>
                              <field name="account_id"/>
                              <field name="journal_id"/>
 -                            <field name="user_id"/>
 +                            <field name="user_id" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'account.group_account_invoice']}"/>
                          </group>
                          <group>
                              <field name="date"/>
                          <filter string="Product" context="{'group_by':'product_id'}"/>
                          <filter string="User" context="{'group_by':'user_id'}"/>
                          <separator/>
 -                        <filter string="Date" context="{'group_by':'date'}" name="group_date"/>
 +                        <filter string="Tasks Month" context="{'group_by':'date'}" name="group_date" help="Invoice Tasks by Month"/>
  
                      </group>
                  </search>
@@@ -40,10 -40,10 +40,10 @@@ class one2many_mod2(fields.one2many)
              plan = journal.plan_id
              if plan and len(plan.plan_ids) > pnum:
                  acc_id = plan.plan_ids[pnum].root_analytic_id.id
 -                ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',ids),('analytic_account_id','child_of',[acc_id])], limit=self._limit)
 +                ids2 = obj.pool[self._obj].search(cr, user, [(self._fields_id,'in',ids),('analytic_account_id','child_of',[acc_id])], limit=self._limit)
          if ids2 is None:
 -            ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',ids)], limit=self._limit)
 -        for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
 +            ids2 = obj.pool[self._obj].search(cr, user, [(self._fields_id,'in',ids)], limit=self._limit)
 +        for r in obj.pool[self._obj]._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
              res[r[self._fields_id]].append( r['id'] )
          return res
  
@@@ -65,6 -65,7 +65,6 @@@ class account_analytic_line(osv.osv)
          'percentage': fields.float('Percentage')
      }
  
 -account_analytic_line()
  
  class account_analytic_plan(osv.osv):
      _name = "account.analytic.plan"
@@@ -74,6 -75,7 +74,6 @@@
          'plan_ids': fields.one2many('account.analytic.plan.line', 'plan_id', 'Analytic Plans'),
      }
  
 -account_analytic_plan()
  
  class account_analytic_plan_line(osv.osv):
      _name = "account.analytic.plan.line"
@@@ -92,6 -94,7 +92,6 @@@
          'max_required': 100.0,
      }
  
 -account_analytic_plan_line()
  
  class account_analytic_plan_instance(osv.osv):
      _name = "account.analytic.plan.instance"
                  vals['code'] = this.code and (str(this.code)+'*') or "*"
          return super(account_analytic_plan_instance, self).write(cr, uid, ids, vals, context=context)
  
 -account_analytic_plan_instance()
  
  class account_analytic_plan_instance_line(osv.osv):
      _name = "account.analytic.plan.instance.line"
              res.append((record['id'], record['analytic_account_id']))
          return res
  
 -account_analytic_plan_instance_line()
  
  class account_journal(osv.osv):
      _inherit = "account.journal"
          'plan_id': fields.many2one('account.analytic.plan', 'Analytic Plans'),
      }
  
 -account_journal()
  
  class account_invoice_line(osv.osv):
      _inherit = "account.invoice.line"
              res_prod['value'].update({'analytics_id': rec.analytics_id.id})
          return res_prod
  
 -account_invoice_line()
  
  class account_move_line(osv.osv):
  
          result = super(account_move_line, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
          return result
  
 -account_move_line()
  
  class account_invoice(osv.osv):
      _name = "account.invoice"
                      il['analytic_lines'].append((0, 0, al_vals))
          return iml
  
 -account_invoice()
  
  class account_analytic_plan(osv.osv):
      _inherit = "account.analytic.plan"
      _columns = {
          'default_instance_id': fields.many2one('account.analytic.plan.instance', 'Default Entries'),
      }
 -account_analytic_plan()
  
  class analytic_default(osv.osv):
      _inherit = "account.analytic.default"
          'analytics_id': fields.many2one('account.analytic.plan.instance', 'Analytic Distribution'),
      }
  
 -analytic_default()
  
  class sale_order_line(osv.osv):
      _inherit = "sale.order.line"
                      inv_line_obj.write(cr, uid, [line.id], {'analytics_id': rec.analytics_id.id}, context=context)
          return create_ids
  
 -sale_order_line()
  
  
  class account_bank_statement(osv.osv):
      _inherit = "account.bank.statement"
      _name = "account.bank.statement"
  
-     def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context=None):
-         account_move_line_pool = self.pool.get('account.move.line')
-         account_bank_statement_line_pool = self.pool.get('account.bank.statement.line')
-         st_line = account_bank_statement_line_pool.browse(cr, uid, st_line_id, context=context)
-         result = super(account_bank_statement,self).create_move_from_st_line(cr, uid, st_line_id, company_currency_id, st_line_number, context=context)
-         move = st_line.move_ids and st_line.move_ids[0] or False
-         if move:
-             for line in move.line_id:
-                 account_move_line_pool.write(cr, uid, [line.id], {'analytics_id':st_line.analytics_id.id}, context=context)
+     def _prepare_bank_move_line(self, cr, uid, st_line, move_id, amount, company_currency_id, context=None):
+         result = super(account_bank_statement,self)._prepare_bank_move_line(cr, uid, st_line, 
+             move_id, amount, company_currency_id, context=context)
+         result['analytics_id'] = st_line.analytics_id.id
          return result
  
      def button_confirm_bank(self, cr, uid, ids, context=None):
                      continue
          return True
  
 -account_bank_statement()
  
  
  class account_bank_statement_line(osv.osv):
      _columns = {
          'analytics_id': fields.many2one('account.analytic.plan.instance', 'Analytic Distribution'),
      }
 -account_bank_statement_line()
  
  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@@ -22,6 -22,7 +22,6 @@@
  import time
  from lxml import etree
  
 -from openerp import netsvc
  from openerp.osv import fields, osv
  import openerp.addons.decimal_precision as dp
  from openerp.tools.translate import _
@@@ -31,14 -32,20 +31,14 @@@ from openerp.report import report_sx
  class res_currency(osv.osv):
      _inherit = "res.currency"
  
 -    def _current_rate(self, cr, uid, ids, name, arg, context=None):
 +    def _get_current_rate(self, cr, uid, ids, raise_on_no_rate=True, context=None):
          if context is None:
              context = {}
 -        res = super(res_currency, self)._current_rate(cr, uid, ids, name, arg, context=context)
 +        res = super(res_currency, self)._get_current_rate(cr, uid, ids, raise_on_no_rate, context=context)
          if context.get('voucher_special_currency') in ids and context.get('voucher_special_currency_rate'):
              res[context.get('voucher_special_currency')] = context.get('voucher_special_currency_rate')
          return res
  
 -    _columns = {
 -        # same definition of rate that in base in order to just overwrite the function
 -        'rate': fields.function(_current_rate, string='Current Rate', digits=(12,6),
 -            help='The rate of the currency to the currency of rate 1.'),
 -    }
 -
  
  class res_company(osv.osv):
      _inherit = "res.company"
@@@ -53,6 -60,7 +53,6 @@@
              domain="[('type', '=', 'other')]",),
      }
  
 -res_company()
  
  class account_config_settings(osv.osv_memory):
      _inherit = 'account.config.settings'
@@@ -97,7 -105,8 +97,7 @@@ class account_voucher(osv.osv)
          if context is None: context = {}
          if context.get('period_id', False):
              return context.get('period_id')
 -        ctx = dict(context, account_period_prefer_normal=True)
 -        periods = self.pool.get('account.period').find(cr, uid, context=ctx)
 +        periods = self.pool.get('account.period').find(cr, uid, context=context)
          return periods and periods[0] or False
  
      def _make_journal_search(self, cr, uid, ttype, context=None):
          return vals
  
      def button_proforma_voucher(self, cr, uid, ids, context=None):
 -        context = context or {}
 -        wf_service = netsvc.LocalService("workflow")
 -        for vid in ids:
 -            wf_service.trg_validate(uid, 'account.voucher', vid, 'proforma_voucher', cr)
 +        self.signal_proforma_voucher(cr, uid, ids)
          return {'type': 'ir.actions.act_window_close'}
  
      def proforma_voucher(self, cr, uid, ids, context=None):
          return True
  
      def action_cancel_draft(self, cr, uid, ids, context=None):
 -        wf_service = netsvc.LocalService("workflow")
 -        for voucher_id in ids:
 -            wf_service.trg_create(uid, 'account.voucher', voucher_id, cr)
 +        self.create_workflow(cr, uid, ids)
          self.write(cr, uid, ids, {'state':'draft'})
          return True
  
      def cancel_voucher(self, cr, uid, ids, context=None):
          reconcile_pool = self.pool.get('account.move.reconcile')
          move_pool = self.pool.get('account.move')
+         move_line_pool = self.pool.get('account.move.line')
          for voucher in self.browse(cr, uid, ids, context=context):
              # refresh to make sure you don't unlink an already removed move
              voucher.refresh()
-             recs = []
              for line in voucher.move_ids:
                  if line.reconcile_id:
-                     recs += [line.reconcile_id.id]
-                 if line.reconcile_partial_id:
-                     recs += [line.reconcile_partial_id.id]
-             reconcile_pool.unlink(cr, uid, recs)
+                     move_lines = [move_line.id for move_line in line.reconcile_id.line_id]
+                     move_lines.remove(line.id)
+                     reconcile_pool.unlink(cr, uid, [line.reconcile_id.id])
+                     if len(move_lines) >= 2:
+                         move_line_pool.reconcile_partial(cr, uid, move_lines, 'auto',context=context)
              if voucher.move_id:
                  move_pool.button_cancel(cr, uid, [voucher.move_id.id])
                  move_pool.unlink(cr, uid, [voucher.move_id.id])
@@@ -1583,6 -1595,7 +1581,6 @@@ class account_voucher_line(osv.osv)
              'type':ttype
          })
          return values
 -account_voucher_line()
  
  class account_bank_statement(osv.osv):
      _inherit = 'account.bank.statement'
  
      def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, next_number, context=None):
          voucher_obj = self.pool.get('account.voucher')
 -        wf_service = netsvc.LocalService("workflow")
          move_line_obj = self.pool.get('account.move.line')
          bank_st_line_obj = self.pool.get('account.bank.statement.line')
          st_line = bank_st_line_obj.browse(cr, uid, st_line_id, context=context)
                              context=context)
              if st_line.voucher_id.state == 'cancel':
                  voucher_obj.action_cancel_draft(cr, uid, [st_line.voucher_id.id], context=context)
 -            wf_service.trg_validate(uid, 'account.voucher', st_line.voucher_id.id, 'proforma_voucher', cr)
 +            voucher_obj.signal_proforma_voucher(cr, uid, [st_line.voucher_id.id])
  
              v = voucher_obj.browse(cr, uid, st_line.voucher_id.id, context=context)
              bank_st_line_obj.write(cr, uid, [st_line_id], {
                      raise osv.except_osv(_('Unable to Change Journal!'), _('You can not change the journal as you already reconciled some statement lines!'))
          return super(account_bank_statement, self).write(cr, uid, ids, vals, context=context)
  
 -account_bank_statement()
  
  class account_bank_statement_line(osv.osv):
      _inherit = 'account.bank.statement.line'
          voucher_obj.unlink(cr, uid, unlink_ids, context=context)
          return super(account_bank_statement_line, self).unlink(cr, uid, ids, context=context)
  
 -account_bank_statement_line()
  
  def resolve_o2m_operations(cr, uid, target_osv, operations, fields, context):
      results = []
              <field name="model">crm.case.stage</field>
              <field name="arch" type="xml">
                  <search string="Stage Search">
 -                    <field name="name" string="Stage Name"/>
 -                    <field name="state"/>
 +                    <field name="name"/>
                      <field name="type"/>
 +                    <field name="sequence"/>
 +                    <field name="probability"/>
                  </search>
              </field>
          </record>
@@@ -79,9 -78,9 +79,9 @@@
                  view_type="form"/>
  
          <act_window
 -                id="act_crm_opportunity_crm_meeting_new"
 +                id="act_crm_opportunity_calendar_event_new"
                  name="Meetings"
 -                res_model="crm.meeting"
 +                res_model="calendar.event"
                  view_mode="tree,form,calendar"
                  context="{'default_duration': 4.0, 'default_opportunity_id': active_id}"
                  view_type="form"/>
              <form string="Leads Form" version="7.0">
                  <header>
                      <button name="%(crm.action_crm_lead2opportunity_partner)d" string="Convert to Opportunity" type="action"
 -                            states="draft,open,pending" help="Convert to Opportunity" class="oe_highlight"/>
 -                    <button name="case_reset" string="Reset" type="object"
 -                            states="cancel"/>
 -                    <button name="case_cancel" string="Cancel Case" type="object"
 -                            states="draft,open,pending"/>
 +                            help="Convert to Opportunity" class="oe_highlight"/>
                      <field name="stage_id" widget="statusbar" clickable="True"
                              domain="['&amp;', '|', ('case_default', '=', True), ('section_ids', '=', section_id), '|', ('type', '=', type), ('type', '=', 'both')]"
 +                            options="{'fold_field': 'fold'}"
                              on_change="onchange_stage_id(stage_id)"/>
                  </header>
                  <sheet>
                              <field name="partner_name" string="Company Name"/>
                              <!-- Preload all the partner's information -->
                              <field name="partner_id" string="Customer"
 -                                on_change="on_change_partner(partner_id)"
 +                                on_change="on_change_partner_id(partner_id)"
                                  options='{"create_name_field": "name"}'
                                  context="{'default_name': contact_name, 'default_street': street, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_function': function, 'default_phone': phone, 'default_mobile': mobile, 'default_fax': fax, 'default_email': email_from, 'default_user_id': user_id, 'default_section_id': section_id}"/>
                              <label for="street" string="Address"/>
                              <field name="phone"/>
                              <field name="mobile"/>
                              <field name="fax"/>
 -                            <!--
 -                            This should be integrated in Open Chatter
 -                            <button string="Mail"
 -                                name="%(mail.action_email_compose_message_wizard)d"
 -                                icon="terp-mail-message-new" type="action" colspan="1"/>
 -                            -->
                          </group>
                          <group>
 -                            <field name="user_id" on_change="on_change_user(user_id, context)"/>
 -                            <label for="section_id"/>
 -                            <div>
 +                            <field name="user_id" on_change="on_change_user(user_id, context)"
 +                                context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_sale_salesman_all_leads'] }"/>
 +                            <label for="section_id" groups="base.group_multi_salesteams"/>
 +                            <div groups="base.group_multi_salesteams">
                                  <field name="section_id"/>
 -                                <button name="case_escalate" string="Escalate" type="object" attrs="{'invisible': ['|', ('section_id','=',False), ('state', 'not in', ['draft','open','pending'])]}"/>
 +                                <button name="case_escalate" string="Escalate"
 +                                        type="object" class="oe_link"
 +                                        attrs="{'invisible': ['|', ('section_id','=',False), ('probability', '=', 100)]}"/>
                              </div>
                              <field name="type" invisible="1"/>
                          </group>
                              <group string="Categorization" groups="base.group_multi_company,base.group_no_one" name="categorization">
                                  <field name="company_id"
                                      groups="base.group_multi_company"
 -                                    widget="selection" colspan="2"/>
 -                                <field name="state" groups="base.group_no_one"/>
 +                                    widget="selection"/>
                              </group>
                              <group string="Mailings">
                                  <field name="opt_out"/>
 +                                <field name="message_bounce"/>
                              </group>
                              <group string="Misc">
 +                                <field name="probability" groups="base.group_no_one"/>
                                  <field name="active"/>
                                  <field name="referred"/>
                              </group>
 +                            <group>
 +                                <field name="date_open" groups="base.group_no_one"/>
 +                                <field name="date_closed" groups="base.group_no_one"/>
 +                            </group>
                          </group>
                      </page>
                      </notebook>
              <field name="model">crm.lead</field>
              <field name="arch" type="xml">
                  <graph string="Opportunities" type="bar">
 -                    <field name="stage_id"/>
 -                    <field name="planned_revenue" operator="+"/>
 +                    <field name="stage_id" type="row"/>
 +                    <field name="planned_revenue" type="measure"/>
                  </graph>
              </field>
          </record>
              <field name="name">Leads</field>
              <field name="model">crm.lead</field>
              <field name="arch" type="xml">
 -                <tree string="Leads" fonts="bold:message_unread==True" colors="grey:state in ('cancel', 'done')">
 +                <tree string="Leads" fonts="bold:message_unread==True" colors="grey:probability == 100">
                      <field name="date_deadline" invisible="1"/>
                      <field name="create_date"/>
                      <field name="name"/>
                      <field name="stage_id"/>
                      <field name="user_id" invisible="1"/>
                      <field name="partner_id" invisible="1"/>
 -                    <field name="section_id" invisible="context.get('invisible_section', True)"/>
 -                    <field name="state" invisible="1"/>
 +                    <field name="section_id" invisible="context.get('invisible_section', True)" groups="base.group_multi_salesteams"/>
 +                    <field name="probability" invisible="1"/>
                      <field name="type_id" invisible="1"/>
                      <field name="referred" invisible="1"/>
                      <field name="channel_id" invisible="1"/>
              <field name="model">crm.lead</field>
              <field name="arch" type="xml">
                  <kanban default_group_by="stage_id">
 -                    <field name="state" groups="base.group_no_one"/>
                      <field name="stage_id"/>
                      <field name="color"/>
                      <field name="priority"/>
                  <search string="Search Leads">
                      <field name="name" string="Lead / Customer" filter_domain="['|','|','|',('partner_name','ilike',self),('email_from','ilike',self),('contact_name','ilike',self),('name','ilike',self)]"/>
                      <field name="categ_ids" string="Category" filter_domain="[('categ_ids','ilike',self)]"/>
 -                    <field name="section_id" context="{'invisible_section': False}"/>
 +                    <field name="section_id" context="{'invisible_section': False}" groups="base.group_multi_salesteams"/>
                      <field name="user_id"/>
-                     <field name="partner_id" filter_domain="[('partner_id','child_of',self)]"/>
+                     <field name="partner_id" operator="child_of"/>
                      <field name="create_date"/>
                      <field name="country_id" context="{'invisible_country': False}"/>
                      <separator/>
 -                    <filter string="Open" name="open" domain="[('state','!=','cancel')]" help="Open Leads"/>
 -                    <filter string="Dead" name="dead" domain="[('state','=','cancel')]"/>
 -                    <filter string="Unassigned" domain="[('user_id','=', False)]" help="No salesperson"/>
 -                    <filter string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]" help="Unread messages"/>
 -                    <filter string="Assigned to Me"
 +                    <filter string="Unassigned" name="unassigned"
 +                            domain="[('user_id','=', False)]"
 +                            help="No salesperson"/>
 +                    <filter string="My Leads"
                              domain="[('user_id','=',uid)]" context="{'invisible_section': False}"
                              help="Leads that are assigned to me"/>
 -                    <filter string="Assigned to My Team(s)"
 +                    <filter string="My Team(s)" groups="base.group_multi_salesteams"
                              domain="[('section_id.member_ids', 'in', [uid])]" context="{'invisible_section': False}"
                              help="Leads that are assigned to any sales teams I am member of"/>
 +                    <filter string="Dead" name="dead"
 +                            domain="[('probability', '=', '0'), ('stage_id.fold', '=', True)]"/>
 +                    <filter string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]"/>
                      <separator />
                      <filter string="Available for mass mailing"
                              name='not_opt_out' domain="[('opt_out', '=', False)]"
                      <separator />
                      <group expand="0" string="Group By...">
                          <filter string="Salesperson" domain="[]" context="{'group_by':'user_id'}"/>
 -                        <filter string="Team" domain="[]" context="{'group_by':'section_id'}"/>
 +                        <filter string="Team" domain="[]" context="{'group_by':'section_id'}" groups="base.group_multi_salesteams"/>
                          <filter string="Stage" domain="[]" context="{'group_by':'stage_id'}"/>
                          <filter string="Customer" help="Partner" domain="[]" context="{'group_by':'partner_id'}"/>
                          <filter string="Country" domain="[]" context="{'group_by':'country_id'}"/>
                      </group>
                      <group string="Display">
                          <filter string="Show Countries" context="{'invisible_country': False}" help="Show Countries"/>
 -                        <filter string="Show Sales Team" context="{'invisible_section': False}" domain="[]" help="Show Sales Team"/>
 +                        <filter string="Show Sales Team" context="{'invisible_section': False}" domain="[]" help="Show Sales Team" groups="base.group_multi_salesteams"/>
                      </group>
                  </search>
              </field>
              <field name="arch" type="xml">
                  <form string="Opportunities" version="7.0">
                      <header>
 -                        <button name="case_mark_won" string="Mark Won" type="object"
 -                                states="draft,open,pending" class="oe_highlight"/>
 -                        <button name="case_mark_lost" string="Mark Lost" type="object"
 -                                states="draft,open" class="oe_highlight"/>
 -                        <field name="stage_id" widget="statusbar" clickable="True"/>
 +                        <button name="case_mark_won" string="Mark Won" type="object" class="oe_highlight"/>
 +                        <button name="case_mark_lost" string="Mark Lost" type="object" class="oe_highlight"/>
 +                        <field name="stage_id" widget="statusbar" clickable="True"
 +                            options="{'fold_field': 'fold'}"
 +                            domain="['&amp;', ('section_ids', '=', section_id), '|', ('type', '=', type), ('type', '=', 'both')]"/>
                      </header>
                      <sheet>
                          <div class="oe_right oe_button_box">
 -                            <button string="Schedule/Log Call"
 -                                name="%(opportunity2phonecall_act)d"
 -                                type="action"/>
 -                            <button string="Meeting"
 +                            <button string="Schedule/Log Call" type="action"
 +                                name="%(opportunity2phonecall_act)d"/>
 +                            <button string="Meeting" type="object"
                                  name="action_makeMeeting"
 -                                type="object"
                                  context="{'search_default_attendee_id': active_id, 'default_attendee_id' : active_id}"/>
                          </div>
                          <div class="oe_title">
                          <group>
                              <group>
                                  <field name="partner_id"
 -                                    on_change="onchange_partner_id(partner_id, email_from)"
 +                                    on_change="on_change_partner_id(partner_id)"
                                      string="Customer"
                                      context="{'default_name': partner_name, 'default_email': email_from, 'default_phone': phone}"/>
                                  <field name="email_from" string="Email" widget="email"/>
                              </group>
  
                              <group>
 -                                <field name="user_id" on_change="on_change_user(user_id, context)"/>
 -                                <label for="section_id"/>
 -                                <div>
 +                                <field name="user_id" on_change="on_change_user(user_id, context)" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_sale_salesman_all_leads']}"/>
 +                                <label for="section_id" groups="base.group_multi_salesteams"/>
 +                                <div groups="base.group_multi_salesteams">
                                      <field name="section_id" widget="selection"/>
 -                                    <button name="case_escalate" string="Escalate" type="object" class="oe_link" attrs="{'invisible': ['|', ('section_id','=',False), ('state', 'not in', ['draft','open','pending'])]}"/>
 +                                    <button name="case_escalate" string="Escalate" type="object" class="oe_link"
 +                                            attrs="{'invisible': ['|', ('section_id','=',False), ('probability', '=', 100)]}"/>
                                  </div>
                              </group>
                              <group>
                                  <field name="categ_ids"
                                      string="Categories" widget="many2many_tags"
 -                                    context = "{'object_name': 'crm.lead'}"
 +                                    context="{'object_name': 'crm.lead'}"
                                      domain="[('object_id.model', '=', 'crm.lead')]"/>
  
                              </group>
                                      <field name="day_open" groups="base.group_no_one"/>
                                      <field name="day_close" groups="base.group_no_one"/>
                                      <field name="referred"/>
 -                                    <field name="state" invisible="1"/>
                                      <field name="type" invisible="1"/>
                                  </group>
                                  <group string="References">
              <field name="name">Opportunities Tree</field>
              <field name="model">crm.lead</field>
              <field name="arch" type="xml">
 -                <tree string="Opportunities" fonts="bold:message_unread==True" colors="gray:state in ('cancel', 'done');red:date_deadline and (date_deadline &lt; current_date)">
 +                <tree string="Opportunities" fonts="bold:message_unread==True" colors="gray:probability == 100;red:date_deadline and (date_deadline &lt; current_date)">
                      <field name="date_deadline" invisible="1"/>
                      <field name="create_date"/>
                      <field name="name" string="Opportunity"/>
                      <field name="stage_id"/>
                      <field name="planned_revenue" sum="Expected Revenues"/>
                      <field name="probability" avg="Avg. of Probability"/>
 -                    <field name="section_id" invisible="context.get('invisible_section', True)"/>
 +                    <field name="section_id" invisible="context.get('invisible_section', True)" groups="base.group_multi_salesteams"/>
                      <field name="user_id"/>
                      <field name="referred" invisible="1"/>
                      <field name="priority" invisible="1"/>
                      <field name="message_unread" invisible="1"/>
 -                    <field name="state" invisible="1"/>
 +                    <field name="probability" invisible="1"/>
 +                    <field name="write_date" invisible="1"/>
                  </tree>
              </field>
          </record>
                  <search string="Search Opportunities">
                      <field name="name" string="Opportunity" filter_domain="['|','|','|',('partner_id','ilike',self),('partner_name','ilike',self),('email_from','ilike',self),('name', 'ilike', self)]"/>
                      <field name="categ_ids" string="Category" filter_domain="[('categ_ids','ilike', self)]"/>
 -                    <field name="section_id" context="{'invisible_section': False}"/>
 +                    <field name="section_id" context="{'invisible_section': False}" groups="base.group_multi_salesteams"/>
                      <field name="user_id"/>
-                     <field name="partner_id" filter_domain="[('partner_id','child_of',self)]"/>
+                     <field name="partner_id" operator="child_of"/>
 +                    <field name="stage_id" domain="[]"/>
 +                    <field name="probability"/>
                      <separator/>
 -                    <filter string="New" name="new" domain="[('state','=','draft')]" help="New Opportunities"/>
 -                    <filter string="In Progress" name="open" domain="[('state','=','open')]" help="Open Opportunities"/>
 -                    <filter string="Won" name="won" domain="[('state','=','done')]"/>
 -                    <filter string="Lost" name="lost" domain="[('state','=','cancel')]"/>
 -                    <filter string="Unassigned" domain="[('user_id','=', False)]" help="No salesperson"/>
 -                    <filter string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]" help="Unread messages"/>
 -                    <filter string="Assigned to Me"
 -                            domain="[('user_id','=',uid)]" context="{'invisible_section': False}"
 +                    <filter string="Won" name="won"
 +                            domain="[('probability', '=', 100), ('stage_id.fold', '=', True)]"/>
 +                    <filter string="Lost" name="lost"
 +                            domain="[('probability', '=', 0), ('stage_id.fold', '=', True)]"/>
 +                    <filter string="Unassigned" name="unassigned"
 +                            domain="[('user_id','=', False)]" help="No salesperson"/>
 +                    <filter string="My Opportunities" name="assigned_to_me"
 +                            domain="[('user_id', '=', uid)]" context="{'invisible_section': False}"
                              help="Opportunities that are assigned to me"/>
 -                    <filter string="Assigned to My Team(s)"
 +                    <filter string="My Team(s)"
                              domain="[('section_id.member_ids', 'in', [uid])]" context="{'invisible_section': False}"
                              help="Opportunities that are assigned to any sales teams I am member of"/>
 +                    <filter string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]"/>
                      <separator/>
                      <group expand="0" string="Group By..." colspan="16">
                          <filter string="Salesperson" domain="[]" context="{'group_by':'user_id'}"/>
                          <filter string="Campaign" domain="[]" context="{'group_by':'type_id'}"/>
                          <filter string="Channel" domain="[]" context="{'group_by':'channel_id'}"/>
                          <filter string="Creation" domain="[]" context="{'group_by':'create_date'}"/>
 +                        <filter string="Last Update Month" domain="[]" context="{'group_by':'write_date'}"/>
                      </group>
                      <group string="Display">
 -                        <filter string="Show Sales Team" context="{'invisible_section': False}" domain="[]" help="Show Sales Team"/>
 +                        <filter string="Show Sales Team" context="{'invisible_section': False}" domain="[]" help="Show Sales Team" groups="base.group_multi_salesteams"/>
                          <filter string="Show Countries" context="{'invisible_country': False}" help="Show Countries"/>
                      </group>
                  </search>
              </field>
          </record>
  
 +        <!--
 +            MASS MAILING
 +        -->
 +        <act_window name="Lead/Opportunity Mass Mail"
 +                res_model="mail.compose.message"
 +                src_model="crm.lead"
 +                view_mode="form"
 +                multi="True"
 +                target="new"
 +                key2="client_action_multi"
 +                id="crm.action_lead_mass_mail"
 +                context="{
 +                            'default_composition_mode': 'mass_mail',
 +                            'default_email_to':'{($object.email or \'\')|safe}',
 +                            'default_use_template': True,
 +                            'default_template_id': ref('crm.email_template_opportunity_mail'),
 +                        }"
 +                groups="base.group_sale_salesman"
 +                />
 +
 +        <!--Update of email_template defined in crm_lead_data, to add ref_ir_act_window
 +            allowing to have a well formed email template (context action considered as set). -->
 +        <record id="email_template_opportunity_mail" model="email.template">
 +            <field name="ref_ir_act_window" ref="crm.action_lead_mass_mail"/>
 +        </record>
 +
 +        <record id="action_mark_as_lost" model="ir.actions.server">
 +            <field name="name">Mark As Lost</field>
 +            <field name="model_id" ref="model_crm_lead"/>
 +            <field name="state">code</field>
 +            <field name="code">
 +                if context.get('active_model') == 'crm.lead' and context.get('active_ids'):
 +                    self.case_mark_lost(cr, uid, context['active_ids'], context=context)
 +            </field>
 +        </record>
 +
 +        <record id="ir_mark_as_lost" model="ir.values">
 +            <field eval="'client_action_multi'" name="key2"/>
 +            <field eval="'crm.lead'" name="model"/>
 +            <field name="name">Mark As Lost</field>
 +            <field eval="'ir.actions.server,%d'%action_mark_as_lost" name="value"/>
 +        </record>
 +
      </data>
  </openerp>
                  <field name="create_date" invisible="1"/>
                  <field name="opportunity_id" invisible="1"/>
                  <field name="state"/>
 -                <button name="case_open" string="Confirm" type="object"
 -                        states="draft,pending" icon="gtk-go-forward"/>
 -                <button name="case_close" string="Held" type="object"
 -                        states="open,pending" icon="gtk-jump-to"/>
 -                <button name="case_cancel" string="Cancel" type="object"
 -                        states="draft,open,pending" icon="gtk-cancel"/>
 -                <button name="case_reset" string="Reset to Todo" type="object"
 -                        states="cancel" icon="gtk-convert"/>
              </tree>
          </field>
      </record>
          <field name="arch" type="xml">
              <form string="Phone Call" version="7.0">
                  <header>
 -                    <button name="case_close" string="Call Done" type="object" class="oe_highlight"
 -                            states="open,pending"/>
 -                    <button name="case_reset" string="Reset to Todo" type="object"
 -                            states="cancel"/>
 -                    <button name="case_cancel" string="Cancel Call" type="object"
 -                            states="draft,open,pending"/>
 -                    <field name="state" widget="statusbar" nolabel="1" statusbar_visible="open,done"/>
 +                    <field name="state" nolabel="1" widget="statusbar" clickable="True"/>
                  </header>
                  <sheet string="Phone Call">
                      <div class="oe_right">
  
                      <group col="4">
                          <field name="date"/>
 -                        <field name="user_id"/>
 -                        <field name="duration" widget="float_time"/>
 -                        <field name="section_id" colspan="1" widget="selection"/>
 -                        <field name="partner_id" on_change="onchange_partner_id(partner_id)"/>
 -                        <field name="email_from" invisible="1"/> <!--not needed because of the chatter, thus invisible, but must be in the view as it's returned by onchange_partner_id()-->
 +                        <field name="user_id" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_sale_salesman_all_leads']}"/>
 +                        <label for="duration"/>
 +                        <div>
 +                              <field name="duration" widget="float_time" class="oe_inline" style="vertical-align:baseline"/> <b> min(s)</b>
 +                        </div>
 +                        <field name="section_id" colspan="1" widget="selection"
 +                                groups="base.group_multi_salesteams"/>
 +                        <field name="partner_id" on_change="on_change_partner_id(partner_id)"/>
                          <field name="categ_id" widget="selection"
                              domain="[('object_id.model', '=', 'crm.phonecall')]"/>
                          <field name="partner_mobile"/>
                  <field name="date"/>
                  <field name="name"/>
                  <field name="partner_id"
 -                    on_change="onchange_partner_id(partner_id)"/>
 +                    on_change="on_change_partner_id(partner_id)"/>
                  <field name="partner_phone"
                      invisible="1"/>
 -                <field name="user_id"/>
 +                <field name="user_id" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_sale_salesman_all_leads']}"/>
                  <field name="categ_id" widget="selection"
                      domain="[('object_id.model', '=', 'crm.phonecall')]"
                      invisible="1"/>
                 <filter icon="terp-gtk-go-back-rtl" string="To Do" name="current" domain="[('state','=','open')]"/>
                 <separator/>
                 <filter string="Unassigned Phonecalls" icon="terp-personal-" domain="[('user_id','=',False)]" help="Unassigned Phonecalls"/>
 +               <filter string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]"/>
                 <separator/>
                 <filter string="Phone Calls Assigned to Me or My Team(s)" icon="terp-personal+" domain="['|', ('section_id.user_id','=',uid), ('user_id', '=', uid)]"
                         help="Phone Calls Assigned to the current user or with a team having the current user as team leader"/>
-                <field name="partner_id" filter_domain="[('partner_id','child_of',self)]"/>
+                <field name="partner_id" operator="child_of"/>
                 <field name="user_id"/>
 -               <field name="section_id" string="Sales Team"/>
 +               <field name="section_id" string="Sales Team"
 +                        groups="base.group_multi_salesteams"/>
                 <group expand="0" string="Group By...">
                     <filter string="Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
                     <filter string="Responsible" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
                     <filter string="Creation" icon="terp-go-month" help="Creation Date" domain="[]" context="{'group_by':'create_date'}"/>
 -                   <filter string="Date" icon="terp-go-month" domain="[]" context="{'group_by':'date'}" help="Date of Call"/>
 +                   <filter string="Calls Month" icon="terp-go-month" domain="[]" context="{'group_by':'date'}" help="Calls Date by Month"/>
                 </group>
             </search>
          </field>
@@@ -6,53 -6,48 +6,53 @@@
              <field name="model">mail.mail</field>
              <field name="arch" type="xml">
                  <form string="Email message" version="7.0">
 +                    <header>
 +                        <button name="send" string="Send Now" type="object" states='outgoing' class="oe_highlight"/>
 +                        <button name="mark_outgoing" string="Retry" type="object" states='exception,cancel'/>
 +                        <button name="cancel" string="Cancel" type="object" states='outgoing'/>
 +                    </header>
                      <sheet>
                          <field name="mail_message_id" required="0" invisible="1"/>
                          <label for="subject" class="oe_edit_only"/>
                          <h2><field name="subject"/></h2>
 -                        <div>
 +                        <div style="vertical-align: top;">
                              by <field name="author_id" class="oe_inline" string="User"/> on <field name="date" class="oe_inline"/>
                              <button name="%(action_email_compose_message_wizard)d" string="Reply" type="action" icon="terp-mail-replied"
                                  context="{'default_composition_mode':'reply', 'default_parent_id': mail_message_id}" states='received,sent,exception,cancel'/>
                          </div>
 -                        <notebook colspan="4">
 -                            <page string="Message Details">
 -                                <group>
 -                                    <group>
 -                                        <field name="email_from"/>
 -                                        <field name="email_to"/>
 -                                        <field name="email_cc"/>
 -                                        <field name="reply_to"/>
 -                                    </group>
 -                                    <group>
 -                                        <field name="partner_ids" widget="many2many_tags"/>
 -                                    </group>
 -                                </group>
 -                                <notebook>
 -                                    <page string="Body">
 -                                        <field name="body_html"/>
 -                                    </page>
 -                                </notebook>
 +                        <group>
 +                            <field name="email_from"/>
 +                            <field name="email_to"/>
 +                            <field name="recipient_ids" widget="many2many_tags"/>
 +                            <field name="email_cc"/>
 +                            <field name="reply_to"/>
 +                        </group>
 +                        <notebook>
 +                            <page string="Body">
 +                                <field name="body_html"/>
                              </page>
                              <page string="Advanced" groups="base.group_no_one">
                                  <group>
 -                                    <group>
 -                                        <field name="auto_delete"/>
 -                                        <field name="type"/>
 -                                        <field name="state" colspan="2"/>
 -                                        <field name="mail_server_id"/>
 -                                        <field name="model"/>
 -                                        <field name="res_id"/>
 -                                    </group>
 -                                    <group>
 -                                        <field name="message_id"/>
 -                                        <field name="references"/>
 -                                    </group>
 +                                    <div>
 +                                        <group string="Status">
 +                                            <field name="auto_delete"/>
 +                                            <field name="type"/>
 +                                            <field name="state"/>
 +                                            <field name="mail_server_id"/>
 +                                            <field name="model"/>
 +                                            <field name="res_id"/>
 +                                        </group>
 +                                    </div>
 +                                    <div>
 +                                        <group string="Headers">
 +                                            <field name="message_id"/>
 +                                            <field name="references"/>
 +                                        </group>
 +                                        <group string="Recipients">
 +                                            <field name="partner_ids" widget="many2many_tags"/>
 +                                            <field name="notified_partner_ids" widget="many2many_tags"/>
 +                                        </group>
 +                                    </div>
                                  </group>
                              </page>
                              <page string="Attachments">
@@@ -73,7 -68,7 +73,7 @@@
                      <field name="subject"/>
                      <field name="author_id" string="User"/>
                      <field name="message_id" invisible="1"/>
 -                    <field name="partner_ids" invisible="1"/>
 +                    <field name="recipient_ids" invisible="1"/>
                      <field name="model" invisible="1"/>
                      <field name="res_id" invisible="1"/>
                      <field name="email_from" invisible="1"/>
@@@ -91,7 -86,7 +91,7 @@@
              <field name="model">mail.mail</field>
              <field name="arch" type="xml">
                  <search string="Email Search">
-                     <field name="email_from" filter_domain="['|' '|',('email_from','ilike',self), ('email_to','ilike',self), ('subject','ilike',self)]" string="Email"/>
+                     <field name="email_from" filter_domain="['|', '|',('email_from','ilike',self), ('email_to','ilike',self), ('subject','ilike',self)]" string="Email"/>
                      <field name="date"/>
                      <filter icon="terp-camera_test" name="received" string="Received" domain="[('state','=','received')]"/>
                      <filter icon="terp-call-start" name="outgoing" string="Outgoing" domain="[('state','=','outgoing')]"/>
                      <filter icon="terp-camera_test" name="type_notification" string="Notification" domain="[('type','=','notification')]"/>
                      <group expand="0" string="Extended Filters...">
                          <field name="author_id"/>
 -                        <field name="partner_ids"/>
 +                        <field name="recipient_ids"/>
                          <field name="model"/>
                          <field name="res_id"/>
                      </group>
              <field name="res_model">mail.mail</field>
              <field name="view_type">form</field>
              <field name="view_mode">tree,form</field>
 -            <field name="context">{'search_default_outgoing': 1, 'search_default_type_email': 1}</field>
 +            <field name="context">{'search_default_outgoing': 1}</field>
              <field name="search_view_id" ref="view_mail_search"/>
          </record>
  
              <field name="arch" type="xml">
                  <form string="Issue" version="7.0">
                  <header>
 -                    <button name="case_close" string="Done" type="object"
 -                            states="open" groups="base.group_user"/>
 -                    <button name="case_close" string="Done" type="object"
 -                            states="draft,pending" groups="base.group_user"/>
 -                    <button name="case_cancel" string="Cancel Issue" type="object"
 -                            states="draft,open,pending" groups="base.group_user"/>
 -                    <field name="stage_id" widget="statusbar" clickable="True"/>
 +                    <field name="stage_id" widget="statusbar" clickable="True"
 +                        options="{'fold_field': 'fold'}"/>
                  </header>
                  <sheet string="Issue">
                      <label for="name" class="oe_edit_only"/>
 -                    <h1><field name="name"/></h1>
 +                    <h1>
 +                        <field name="name" class="oe_inline"/>
 +                        <field name="kanban_state" invisible='1'/>
 +                        <button name="set_kanban_state_done" help="In Progress" attrs="{'invisible': [('kanban_state', 'in', ['done','blocked'])]}" type="object" icon="gtk-normal" class="oe_link oe_right"/>
 +                        <button name="set_kanban_state_blocked" help="Ready for Next Stage" attrs="{'invisible': [('kanban_state', 'in', ['normal','blocked'])]}" type="object" icon="gtk-yes" class="oe_link oe_right"/>
 +                        <button name="set_kanban_state_normal" help="Blocked" attrs="{'invisible': [('kanban_state', 'in', ['done','normal'])]}" type="object" icon="gtk-no" class="oe_link oe_right"/>
 +                    </h1>
                      <label for="categ_ids" class="oe_edit_only"/>
                      <field name="categ_ids" widget="many2many_tags"/>
                      <group>
 -                        <group groups="base.group_user">
 -                            <field name="user_id"/>
 -                            <field name="partner_id"  on_change="onchange_partner_id(partner_id, email_from)"/>
 +                        <group>
 +                            <field name="user_id" 
 +                                context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'project.group_project_user']}"/>
 +                            <field name="partner_id" on_change="onchange_partner_id(partner_id)"/>
                              <field name="email_from"/>
 -                            <label for="project_id" groups="base.group_user"/>
 -                            <div groups="base.group_user">
 +                            <label for="project_id"/>
 +                            <div>
                                  <field name="project_id" on_change="on_change_project(project_id)" class="oe_inline" context="{'default_use_issues':1}"/>
 -                                <button name="case_escalate" string="⇒ Escalate" type="object" states="draft,open,pending" class="oe_link"/>
 +                                <button name="case_escalate" string="⇒ Escalate" type="object" class="oe_link"
 +                                        groups="base.group_user"/>
                              </div>
                          </group>
                          <group>
@@@ -90,7 -87,7 +90,7 @@@
                          <page string="Description">
                              <field name="description" placeholder="Add an internal note..." groups="base.group_user"/>
                          </page>
 -                        <page string="Extra Info" groups="project.group_project_manager">
 +                        <page string="Extra Info" groups="project.group_project_manager,project.group_project_user">
                              <group string="Statistics">
                                  <field name="day_open"/>
                                  <field name="day_close"/>
                              </group>
                              <group string="Status" groups="base.group_no_one">
                                  <field name="active"/>
 -                                <field name="state" string="Status"/>
                              </group>
                          </page>
                      </notebook>
              <field name="name">Project Issue Tracker Tree</field>
              <field name="model">project.issue</field>
              <field name="arch" type="xml">
 -                <tree string="Issue Tracker Tree" fonts="bold:message_unread==True" colors="black:state=='open';blue:state=='pending';grey:state in ('cancel', 'done')">
 +                <tree string="Issue Tracker Tree" fonts="bold:message_unread==True">
                      <field name="message_unread" invisible="1"/>
                      <field name="id"/>
                      <field name="name"/>
                      <field name="user_id"/>
                      <field name="progress" widget="progressbar" attrs="{'invisible':[('task_id','=',False)]}"/>
                      <field name="stage_id" widget="selection" readonly="1"/>
 -                    <field name="state" invisible="1"/>
                      <field name="categ_ids" invisible="1"/>
                      <field name="task_id" invisible="1"/>
                  </tree>
              <field name="model">project.issue</field>
              <field name="arch" type="xml">
                  <search string="Issue Tracker Search">
 -                    <field name="name" string="Issue" filter_domain="['|', '|',('partner_id','child_of',self),('email_from','ilike',self),('name','ilike',self)]"/>
 +                    <field name="name" string="Issue" filter_domain="['|', '|', '|', ('partner_id','child_of',self), ('description','ilike',self),('email_from','ilike',self),('name','ilike',self)]"/>
                      <field name="id"/>
-                     <field name="partner_id" filter_domain="[('partner_id', 'child_of', self)]"/>
 -                    <filter icon="terp-mail-message-new" string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]"/>
++                    <field name="partner_id" operator="child_of"/>
 +                    <filter string="Unassigned" name="unassigned" domain="[('user_id', '=', False)]"/>
 +                    <filter string="New" name="draft" domain="[('stage_id.sequence', '=', 1)]"/>
                      <separator/>
 -                    <filter string="New" icon="terp-document-new" domain="[('state','=','draft')]" help="New Issues"/>
 -                    <filter string="To Do" domain="[('state','=','open')]" help="To Do Issues" icon="terp-check"/>
 +                    <filter string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]"/>
                      <separator/>
                      <field name="user_id"/>
                      <field name="project_id"/>
                      <field name="categ_ids"/>
 -                    <field name="partner_id" operator="child_of"/>
 +                    <field name="stage_id" domain="[]"/>
                      <group expand="0" string="Group By..." >
 -                        <filter string="Responsible" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
 -                        <filter string="Contact" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
 -                        <filter string="Project"  icon="terp-folder-violet" domain="[]" context="{'group_by':'project_id'}"/>
 -                        <filter string="Version" icon="terp-gtk-jump-to-rtl" domain="[]" context="{'group_by':'version_id'}"/>
 -                        <filter string="Priority" icon="terp-rating-rated" domain="[]" context="{'group_by':'priority'}"/>
 -                        <filter string="Stage" icon="terp-stage" domain="[]" context="{'group_by':'stage_id'}"/>
 -                        <filter string="Month" icon="terp-go-month" domain="[]" context="{'group_by':'create_date'}" help="Creation Month"/>
 +                        <filter string="Responsible" name="group_user_id" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
 +                        <filter string="Contact" name="group_partner_id" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
 +                        <filter string="Project" name="group_project_id" icon="terp-folder-violet" domain="[]" context="{'group_by':'project_id'}"/>
 +                        <filter string="Version" name="group_version" icon="terp-gtk-jump-to-rtl" domain="[]" context="{'group_by':'version_id'}"/>
 +                        <filter string="Priority" name="group_priority" icon="terp-rating-rated" domain="[]" context="{'group_by':'priority'}"/>
 +                        <filter string="Stage" name="group_stage_id" icon="terp-stage" domain="[]" context="{'group_by':'stage_id'}"/>
 +                        <filter string="Creation Month" name="group_create_date" icon="terp-go-month" domain="[]" context="{'group_by':'create_date'}"/>
                      </group>
                  </search>
              </field>
              <field name="name">Project Issue- Feature Tracker Tree</field>
              <field name="model">project.issue</field>
              <field name="arch" type="xml">
 -                <tree string="Feature Tracker Tree" fonts="bold:message_unread==True" colors="red:state=='open';black:state in ('draft', 'cancel','done','pending')">
 +                <tree string="Feature Tracker Tree" fonts="bold:message_unread==True">
                      <field name="id"/>
                      <field name="message_unread" invisible="1"/>
                      <field name="name" string="Feature description"/>
                      <field name="version_id"/>
                      <field name="user_id"/>
                      <field name="stage_id" widget="selection" readonly="1"/>
 -                    <field name="state" groups="base.group_no_one"/>
                  </tree>
              </field>
          </record>
  
 -        <record id="view_project_feature_filter" model="ir.ui.view">
 -            <field name="name">Project Issue - Feature Tracker Search</field>
 -            <field name="model">project.issue</field>
 -            <field name="arch" type="xml">
 -                <search string="Feature Tracker Search">
 -                    <field name="name" string="Feature description"/>
 -                    <field name="date"/>
 -                    <field name="state" groups="base.group_no_one"/>
 -                    <filter icon="terp-check" domain="[('state','in',('open','draft'))]" help="Current Features" name="current_feature"/>
 -                    <filter icon="terp-camera_test" domain="[('state','=','open')]" help="Open Features"/>
 -                    <field name="user_id"/>
 -                    <field name="project_id" string="Project"/>
 -                </search>
 -            </field>
 -        </record>
 -
          <record id="act_project_project_2_project_issue_all" model="ir.actions.act_window">
              <field name="res_model">project.issue</field>
              <field name="view_type">form</field>
              <field name="name">Issues</field>
              <field name="view_mode">kanban,tree,form,calendar,graph</field>
 -            <field name="context">{'search_default_project_id': [active_id], 'default_project_id': active_id}</field>
 +            <field name="context">{
 +                    'search_default_project_id': [active_id], 
 +                    'default_project_id': active_id,
 +                }
 +            </field>
 +            <field name="help" type="html">
 +                <p>
 +                    The OpenERP issues tacker allows you to efficiantly manage things
 +                    like internal requests, software development bugs, customer
 +                    complaints, project troubles, material breakdowns, etc.
 +                </p>
 +            </field>
          </record>
  
          <!-- Project -->
              <field name="inherit_id" ref="project.edit_project"/>
              <field name="arch" type="xml">
                  <xpath expr='//div[@name="options_active"]' position='inside'>
 -                    <field name="use_issues" class="oe_inline"/>
 +                    <field name="use_issues" class="oe_inline"
 +                            on_change="on_change_use_tasks_or_issues(use_tasks, use_issues)"/>
                      <label for="use_issues"/>
                  </xpath>
                  <xpath expr='//div[@name="buttons"]' position='inside'>
                  <xpath expr='//page[@name="project_stages"]' position="attributes">
                      <attribute name="attrs">{'invisible': [('use_tasks', '=', False),('use_issues','=',False)]}</attribute>
                  </xpath>
 -                <field name="priority" position="before">
 +                <xpath expr='//field[@name="use_tasks"]' position="attributes">
 +                    <attribute name="attrs">{'on_change': 'on_change_use_tasks_or_issues(use_tasks, use_issues)'}</attribute>
 +                </xpath>
 +                <field name="sequence" position="before">
                      <field name="project_escalation_id"/>
                  </field>
 -                <field name="alias_domain" position="after">
 -                    <label for="alias_model" class="oe_edit_only" string="creates"/><field name="alias_model" class="oe_edit_only oe_inline"/>
 -                </field>
              </field>
         </record>
  
              <field name="arch" type="xml">
                  <field name="use_tasks" position="after">
                      <field name="use_issues"/>
 -                    <field name="issue_count" invisible="1"/>
 +                    <field name="issue_ids" invisible="1"/>
                  </field>
                  <xpath expr="//div[contains(@class, 'oe_kanban_project_list')]" position="inside">
                      <a t-if="record.use_issues.raw_value" style="margin-right: 10px"
                          name="%(act_project_project_2_project_issue_all)d" type="action">
 -                        <span t-if="record.issue_count.raw_value gt 1"><field name="issue_count"/> Issues</span>
 -                        <span t-if="record.issue_count.raw_value lt 2"><field name="issue_count"/> Issue</span>
 +                        <t t-raw="record.issue_ids.raw_value.length"/>
 +                        <span t-if="record.issue_ids.raw_value.length == 1">Issue</span>
 +                        <span t-if="record.issue_ids.raw_value.length > 1">Issues</span>
                      </a>
                  </xpath>
              </field>
              </field>
          </record>
  
 +        <record id="action_view_issues" model="ir.actions.act_window">
 +            <field name="res_model">project.issue</field>
 +            <field name="view_type">form</field>
 +            <field name="name">Issues</field>
 +            <field name="view_mode">kanban,tree,form,calendar,graph</field>
 +            <field name="help" type="html">
 +                <p>
 +                    The OpenERP issues tacker allows you to efficiantly manage things
 +                    like internal requests, software development bugs, customer
 +                    complaints, project troubles, material breakdowns, etc.
 +                </p>
 +            </field>
 +        </record>
 +
 +        <!-- res.partner -->
 +        <record model="ir.ui.view" id="res_partner_issues_button_view">
 +            <field name="name">res.partner.issues.button.view</field>
 +            <field name="model">res.partner</field>
 +            <field name="inherit_id" ref="base.view_partner_form" />
 +            <field name="priority" eval="50"/>
 +            <field name="arch" type="xml">
 +                <xpath expr="//div[@name='buttons']" position="inside">
 +                    <button class="oe_inline" type="action" string="Issues"
 +                        attrs="{'invisible': [('customer', '=', False)]}"
 +                        name="%(action_view_issues)d"
 +                        context="{'search_default_partner_id': active_id, 'default_partner_id': active_id}"
 +                        groups="project.group_project_user"/>
 +                </xpath>
 +            </field>
 +        </record>
 +
      </data>
  </openerp>
              action="product.product_pricelist_action_for_purchase" id="menu_product_pricelist_action2_purchase"
              parent="menu_purchase_config_pricelist" sequence="1" groups="product.group_purchase_pricelist" />
  
 +      <menuitem
 +          action="product.product_pricelist_action_for_purchase" id="menu_product_pricelist_action2_purchase"
 +          parent="menu_purchase_config_pricelist" sequence="1" groups="product.group_purchase_pricelist" />
 +
          <menuitem
              action="purchase_pricelist_version_action" id="menu_purchase_pricelist_version_action"
              parent="menu_purchase_config_pricelist" sequence="2" groups="product.group_purchase_pricelist"/>
 -
          
          <menuitem
              action="product.product_price_type_action" id="menu_product_pricelist_action2_purchase_type"
@@@ -76,7 -73,7 +76,7 @@@
              parent="menu_purchase_config_purchase"/>
  
          <menuitem
 -            action="base.action_partner_category_form" id="menu_partner_categories_in_form" name="Partner Categories"
 +            action="base.action_partner_category_form" id="menu_partner_categories_in_form" name="Partner Tags"
              parent="purchase.menu_purchase_partner_cat" groups="base.group_no_one"/>
  
      <!--Supplier menu-->
                      <button name="purchase_approve" states="confirmed" string="Approve Order" class="oe_highlight" groups="purchase.group_purchase_manager"/>
                      <button name="view_picking" string="Receive Products" type="object" attrs="{'invisible': ['|', ('shipped','=',True), ('state','!=', 'approved')]}" class="oe_highlight"/>
                      <button name="view_invoice" string="Receive Invoice" type="object" attrs="{'invisible': ['|', ('invoice_method','in', ['picking', 'manual']), '|', ('state','!=', 'approved'), ('invoiced','=',True) ]}" class="oe_highlight"/>
 -                    <button name="action_cancel_draft" states="cancel,sent,confirmed" string="Set to Draft" type="object" />
 -                    <button name="purchase_cancel" states="draft,confirmed,sent" string="Cancel Order"/>
 +                    <button name="action_cancel_draft" states="cancel,confirmed" string="Set to Draft" type="object" />
 +                    <button name="purchase_cancel" states="draft,confirmed,sent" string="Cancel"/>
                      <field name="state" widget="statusbar" statusbar_visible="draft,sent,approved,done" statusbar_colors='{"except_picking":"red","except_invoice":"red","confirmed":"blue"}' readonly="1"/>
                  </header>
                  <sheet>
                              <field name="partner_id" on_change="onchange_partner_id(partner_id)" context="{'search_default_supplier':1,'default_supplier':1,'default_customer':0}" domain="[('supplier','=',True)]"/>
                              <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="currency_id" groups="base.group_multi_currency"/>
                              <field name="journal_id" invisible='1'/>
                          </group>
                          <group>
                              <field name="date_order"/>
                              <field name="origin" attrs="{'invisible': [('origin','=',False)]}"/>
 -                            <field name="warehouse_id" on_change="onchange_warehouse_id(warehouse_id)" widget="selection" groups="stock.group_locations"/>
 +                            <field name="warehouse_id" on_change="onchange_warehouse_id(warehouse_id)" options="{'no_create': True}" groups="stock.group_locations"/>
                              <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                          </group>
                      </group>
                      <filter icon="terp-emblem-important" name="exception" string="Exception" domain="[('state','in',('except_invoice','except_picking'))]" help="Purchase order which are in the exception state"/>
                      <separator/>
                      <filter icon="terp-gtk-go-back-rtl" name="not_invoiced" string="Not Invoiced" domain="[('invoice_ids','=', False)]" help="Purchase orders that include lines not invoiced."/>
-                     <field name="partner_id" filter_domain="[('partner_id', 'child_of', self)]"/>
+                     <field name="partner_id" operator="child_of"/>
                      <field name="product_id"/>
                      <field name="create_uid"/>
                      <group expand="0" string="Group By...">
                      <field name="name" string="Reference"/>
                      <filter icon="terp-mail-message-new" string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]"/>
                      <separator/>
 -                    <filter icon="terp-document-new" name="draft" string="Quotations" domain="[('state','=','draft')]" help="Purchase orders which are in draft state"/>
 +                    <filter icon="terp-document-new" name="draft" string="Quotations" domain="[('state','in',('draft','sent'))]" help="Purchase orders that haven't yet been confirmed"/>
                      <filter icon="terp-check" name="approved" string="Purchase Orders" domain="[('state','not in',('draft','cancel'))]" help="Approved purchase orders"/>
                      <filter icon="terp-emblem-important" name="exception" string="Exception" domain="[('state','in',('except_invoice','except_picking'))]" help="Purchase orders which are in exception state"/>
                      <separator/>
                      <filter icon="terp-gtk-go-back-rtl" name="not_invoiced" string="Not Invoiced" domain="[('invoice_ids','=', False)]" help="Purchase orders that include lines not invoiced."/>
-                     <field name="partner_id" filter_domain="[('partner_id', 'child_of', self)]"/>
+                     <field name="partner_id" operator="child_of"/>
                      <field name="product_id"/>
                      <field name="create_uid"/>
                      <group expand="0" string="Group By...">
                          <filter string="Supplier" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
                          <filter string="Source" icon="terp-gtk-jump-to-rtl" domain="[]" context="{'group_by':'origin'}"/>
                          <filter string="Status" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
 -                        <filter string="Order Date" icon="terp-go-month" domain="[]" context="{'group_by':'date_order'}"/>
 -                        <filter string="Expected Date" icon="terp-go-month" domain="[]" context="{'group_by':'minimum_planned_date'}"/>
 +                        <filter string="Order Month" icon="terp-go-month" domain="[]" context="{'group_by':'date_order'}"/>
 +                        <filter string="Expected Month" icon="terp-go-month" domain="[]" context="{'group_by':'minimum_planned_date'}"/>
                      </group>
                  </search>
              </field>
              <field name="type">ir.actions.act_window</field>
              <field name="res_model">purchase.order</field>
              <field name="context">{}</field>
 -            <field name="domain">[('state','in',('draft','sent','confirmed'))]</field>
 +            <field name="domain">[('state','in',('draft','sent','cancel', 'confirmed'))]</field>
              <field name="view_mode">tree,form,graph,calendar</field>
              <field name="search_view_id" ref="view_purchase_order_filter"/>
              <field name="help" type="html">
              </field>
          </record>
  
 -        <act_window
 -            context="{'search_default_product_id': [active_id], 'default_product_id': active_id}"
 -            id="action_purchase_line_product_tree"
 -            name="Purchases"
 -            res_model="purchase.order.line"
 -            src_model="product.product"
 -            groups="purchase.group_purchase_user"/>
 -
 -
          <record id="purchase_line_form_action2" model="ir.actions.act_window">
              <field name="name">On Purchase Order Lines</field>
              <field name="type">ir.actions.act_window</field>
              <field name="inherit_id" ref="product.product_normal_form_view"/>
              <field name="arch" type="xml">
                  <div name="options" position="inside">
 -                    <field name="purchase_ok"/>
 +                    <field name="purchase_ok" attrs="{'readonly': [('is_only_child', '=', False)]}"/>
                      <label for="purchase_ok"/>
                  </div>
                  <group name="procurement" position="after">
              </field>
          </record>
  
 +        <record id="product_template_search_view_purchase" model="ir.ui.view">
 +            <field name="name">product.template.search.purchase</field>
 +            <field name="model">product.template</field>
 +            <field name="inherit_id" ref="product.product_template_search_view"/>
 +            <field name="arch" type="xml">
 +                <filter name="filter_to_sell" position="after">
 +                    <filter name="filter_to_purchase" string="Can be Purchased" icon="terp-accessories-archiver+" domain="[('purchase_ok', '=', 1)]"/>
 +                </filter>
 +            </field>
 +        </record>
 +
          <record id="view_template_purchase_ok_form" model="ir.ui.view">
              <field name="name">product.template.purchase.ok.form.inherit</field>
              <field name="model">product.template</field>
              <field name="inherit_id" ref="product.product_template_form_view"/>
              <field name="arch" type="xml">
 -                <field name="sale_ok" position="after">
 +                <div name="options" position="inside">
                      <field name="purchase_ok"/>
 -                </field>
 +                    <label for="purchase_ok"/>
 +                </div>
              </field>
          </record>
 -  
 +        <record model="ir.actions.act_window" id="action_purchase_line_product_tree">
 +            <field name="context">{'search_default_product_id': active_id, 'default_product_id': active_id}</field>
 +            <field name="name">Purchases</field>
 +            <field name="res_model">purchase.order.line</field>
 +            <field name="view_id" ref="purchase_order_line_tree"/>
 +        </record>
          <record id="view_product_account_purchase_ok_form" model="ir.ui.view">
              <field name="name">product.account.purchase.ok.form.inherit</field>
              <field name="model">product.product</field>
              <field name="inherit_id" ref="account.product_normal_form_view"/>
              <field name="arch" type="xml">
 -                <xpath expr="//field[@name='property_account_expense']" position="replace" >
 -                     <field name="property_account_expense" domain="[('type','&lt;&gt;','view'),('type','&lt;&gt;','consolidation')]" attrs="{'readonly':[('purchase_ok','=',0)]}" groups="account.group_account_user"/>
 +                <xpath expr="//div[@name='buttons']" position="inside">
 +                   <button string="Purchases" name="%(action_purchase_line_product_tree)d" type="action" groups="purchase.group_purchase_user"/>
                  </xpath>
 -                <xpath expr="//field[@name='supplier_taxes_id']" position="replace" >
 +                <field name="property_account_expense" position="replace" >
 +                     <field name="property_account_expense" domain="[('type','&lt;&gt;','view'),('type','&lt;&gt;','consolidation')]" attrs="{'readonly':[('purchase_ok','=',0)]}" groups="account.group_account_user"/>
 +                </field>
 +                <field name='supplier_taxes_id' position="replace" >
                       <field name="supplier_taxes_id" colspan="2" widget="many2many_tags" attrs="{'readonly':[('purchase_ok','=',0)]}"/>
 -                </xpath>
 +                </field>
              </field>
          </record>
 -
      </data>
  </openerp>
@@@ -6,6 -6,7 +6,6 @@@
              <field name="partner_id" ref="base.res_partner_2"/>
              <field name="partner_invoice_id" ref="base.res_partner_2"/>
              <field name="partner_shipping_id" ref="base.res_partner_2"/>
 -            <field name="shop_id" ref="sale_shop_1"/>
              <field name="user_id" ref="base.user_demo"/>
              <field name="pricelist_id" ref="product.list0"/>
          </record>
@@@ -44,6 -45,7 +44,6 @@@
              <field name="partner_id" ref="base.res_partner_7"/>
              <field name="partner_invoice_id" ref="base.res_partner_address_13"/>
              <field name="partner_shipping_id" ref="base.res_partner_address_13"/>
 -            <field name="shop_id" ref="sale_shop_1"/>
              <field name="user_id" ref="base.user_root"/>
              <field name="pricelist_id" ref="product.list0"/>
              <field name="order_policy">manual</field>
@@@ -73,6 -75,7 +73,6 @@@
              <field name="partner_id" ref="base.res_partner_14"/>
              <field name="partner_invoice_id" ref="base.res_partner_14"/>
              <field name="partner_shipping_id" ref="base.res_partner_14"/>
 -            <field name="shop_id" ref="sale_shop_1"/>
              <field name="user_id" ref="base.user_root"/>
              <field name="pricelist_id" ref="product.list0"/>
              <field name="order_policy">manual</field>
              <field name="partner_id" ref="base.res_partner_15"/>
              <field name="partner_invoice_id" ref="base.res_partner_address_25"/>
              <field name="partner_shipping_id" ref="base.res_partner_address_25"/>
 -            <field name="shop_id" ref="sale_shop_1"/>
              <field name="user_id" ref="base.user_root"/>
              <field name="pricelist_id" ref="product.list0"/>
          </record>
              <field name="partner_id" ref="base.res_partner_2"/>
              <field name="partner_invoice_id" ref="base.res_partner_2"/>
              <field name="partner_shipping_id" ref="base.res_partner_2"/>
 -            <field name="shop_id" ref="sale_shop_1"/>
              <field name="user_id" ref="base.user_demo"/>
              <field name="pricelist_id" ref="product.list0"/>
          </record>
              <field name="partner_id" ref="base.res_partner_18"/>
              <field name="partner_invoice_id" ref="base.res_partner_18"/>
              <field name="partner_shipping_id" ref="base.res_partner_18"/>
 -            <field name="shop_id" ref="sale_shop_1"/>
              <field name="user_id" ref="base.user_root"/>
              <field name="pricelist_id" ref="product.list0"/>
          </record>
              <field name="partner_id" ref="base.res_partner_15"/>
              <field name="partner_invoice_id" ref="base.res_partner_address_25"/>
              <field name="partner_shipping_id" ref="base.res_partner_address_25"/>
 -            <field name="shop_id" ref="sale_shop_1"/>
              <field name="user_id" ref="base.user_demo"/>
              <field name="pricelist_id" ref="product.list0"/>
              <field name="order_policy">manual</field>
          </record>
  
          <!-- Confirm some Sale Orders-->
 +        <workflow action="order_confirm" model="sale.order" ref="sale_order_4"/>
 +
          <workflow action="order_confirm" model="sale.order" ref="sale_order_7"/>
  
          <record id="message_sale_1" model="mail.message">
@@@ -324,11 -329,10 +324,10 @@@ Thanks!</field
              <field name="type">service</field>
              <field name="list_price">150.0</field>
              <field name="standard_price">100.0</field>
              <field name="uom_id" ref="product.product_uom_day"/>
              <field name="uom_po_id" ref="product.product_uom_day"/>
              <field name="company_id" eval="[]"/>
 -            <field name="image">/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4pLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0//wAARCAB9AJYDASIAAhEBAxEB/8QAHAABAAMAAwEBAAAAAAAAAAAAAAQFBgIDBwEI/8QAPhAAAgIBAgMFBgIJAAsAAAAAAQIAAwQREgUhMQYTQVFhIjJxgZGhFGIHFSNCUrHB0fAkMzQ1RVNygpPh4v/EABgBAQEBAQEAAAAAAAAAAAAAAAABAgME/8QAHREBAQEBAAMBAQEAAAAAAAAAAAERAgMSITETUf/aAAwDAQACEQMRAD8AxmHeEzEu/h9kf1mq7L9o34Ln9zcxbBub2l/gPmJjaho6yYzbtPjrCveq3SxFetgysNQR4ic5552S7WV4eGuHnsTSv+rs8VHkfSbuvMxre77vIqY2jcgDDVh5iESIiICJQ8S4y1WYMfGIGw+23Xn5Tk3GLfZCpX66685PaNzx2xeROumxba1dT1Gs7JWCIiAiIgIiICIiAiIgfnQPtsb0M598bTovJZGtVmyHG4AaztbYtY0fRfEDqZVSVs3aLr7I+87Kci224NW7JWp6qeZ+Er2c91oOTWch6CWFLbKwigADy6yDV8K7TcSxkKfiiUA0Cud236y+we1eQ1L1sRc+mu88ts86FpGgHIdZd8GbfQ415l+czbjfM2rCrLJzWFhJLc5bWP8AsktBI2Hn8Jls0vQwfX21OomhR9eEvZ47Jh6ou8PPNDJZrqnusPSaSt1srDodQ3SYp1K8OJHXQAfUS74VkWV3rQ3NX+xmua4+TjfsXsRE285ERAREQEREBERA/N9x0vM62O5wvzM78mtlYPoQrDkZ1VVnRnMivlWrWrr6tJ9ZOsiVrtYHzElpzTUdRKRyQkljLXgl/d5DoTyYbh8R1lcFBVnHLXrPqblYFW0Ye0rDzkv1qXLrS8RoXIo3KRuHQyUbO64MEY+/tWW/Z7Ls4lwyqrIusZbqdhCnkpGqkdPSU2bjvXdj4lw9pHAPy8f885izHo48k61cK+7CRD1ZlH3Bl3wkCzNJHPYNTKIg76K/H3tNJr8DGTGx1AXRmALnzMsiea5EuIibeUiIgIiICIiAiIgYLsLw/C4r2ayMXPxq761yCQGHTkOY8pG43+jxwjPwi0MvhTZop+R6Sb+jKwfgc2v+F1b6gj+kveIZ9pcrRqd3sqvmPEyVXmNPY3ixDnISvFNfIC1x7X01nEdm+K0N7eIzqeQaoh9fpznomSgvKVMfZYkt8BId2Pj0jar27vymTTWDGBeqtW9bK+um0iaJ+xWQnBBe1yLl++KGOh08vjJ/4m1X2LlkAHoX5zswa7OKZIpqsLL+879B/eNNReBL+p+G99nulCVO7ud4OgOgHTx1DcuszvaDtPfxTM3YNZppXT2tPabT+Qnp2X2a4ZmYa42RUzKviGIOvnIvC+xfBuG3d6ldl7g6r35DBfkAJcNReyFVfFeGV5uUv7euxkO3oQNNNRNb4TgiKu4qoG46nQdTOcperf0iIhCIiAiIgIiICIiB5n2c/FcHrvX2CbgFIBPLSWwzrBYX2LrpoPSQFb6yJflWq5roqZnXrrynPder05kXC59q26lEJ2bRK7iFr27TqVYuOQPWRKzxGw/7OyDzbp9pOx8NbFU5FQyD+W4rp8pcc+rxnxW2Mldmqg2NrzPQf+5d8ObWtHpYV268l1/lOstgrojM+Pz00vAKa/8AUOnznO7CKXqawVcHXb6eayuDX8Mzhk17LOVqjmPOT5lcG9L7dayUtXpr/nSaDDylyFIPKxeTCVUqInzXnpKPsREBERAREQEREBERA8zqtG6dzIrXV3aAtWdRr/nrKJcrTxk7F4gNQrGc3ridwh8vCrWu698hR42Hn9ZeM+NkYxydrbVO1nUe0p9fOU+LXdnZaU0j3m0J06DxM3C4NNeEMVFGxRy18ZqOXl9Z+MpkYqXBXZ0spPuWqNdfQyNjtkY+S2N3ZsxxzFY5GseaH+nSdlrfqjiT1NzpuPNGPJx/Q+v185OTZW9bro1D+45HNfMH1hwx8oVK71tTmLOlg6N8fIy6xNDxA8ui8/vIN2OHuRKFDFxq666Bh4H4+sncLxrMe61bCSQNAfTwhVpOjIO3RgTr4DzneJC4rk0YvD7rcl3SsDQmv3h8PWaHNbHavVWU6jkZExbc2m7ZlOl1Z/eUbSvy8pi8DtrZhu1PEEe+vd7NqgK2nqvQzS43FsfLxhl03OKW/e27lB8uXT56TOtWXn40IsTXTeNfjD2InvMBKiu8XjWlqrgP+W4YfbWQ+K8QfAWsBAHtbap8pbUk24v1yqmbbuIM7gwPQ6zIY/GMgOe87tlHoJY/rWohTuYH8q8/hGtdePqL+JT0cbo3bbS4HgdJa12JagetgynoRKzZY5xEQjwgWnxkrGdrHUctZHorrdW3L89ZuexHAuHZWK2bfWbbUsKhGOq9Bz08ZjHWdr3sliCnhnfsPbtPI/ll/OKqFUBQAByAE5Tbnbt1mu1WAuRSthXUA85XcI3G44O03VsNdeu3y+c12bSt+M6MNeU6OG4NeJXu09thzJ6zNn1HVwvE7jczHU+f8pZgQAJ9mgkfMxKc3GfHyU31v1EkRA8v7RdmcnhzvYqNdh9RYOqj8395W8IysnhGT32G42N79Te649f7z2AgMCCNQZmeL9jsXMfvsFxiWeKhdUPy8PlM5/jrPJL86ZzNzOB5dn4hlyca3T91Dy+h0+0psjMxa7QyZmXkBfdU09PrpLfO7OcVwgxsxe+rHPvKTu+3X7SmHdNrt01mWpzz+yuyniLqqtYrLu85fY+dXZV46TN2bLNVblOFDW4raBtyGG9a2uxG5gjnJeFxG7BY922qHqp6TNY+Uug0Ohkhcsr1lS/Wxr7SJppZjsD+U6xMsLww1B0iT2qfz5ZLFPJvhN9+ji/dXmUa9NrfzE8+pOjsBNf+jixhxm5PBqTr8iJ1ed6TERIEREBERAREQEREBM/xbsnw3iLNaqHGyDz7yvoT6jxmgiCXGFPYCw2f7xXb591z+ms7B2AUf8TP/h/+ptokyNe1ef5vYTNRN+Hm1WsP3WQpr9zMzxLD4rw1v9Pxbal10D6aqf8AuHKezTiwDDawBB5aGMWd2PE04i4GhMT0viHY3g3EHFncnHbXn3J2g/LpEzjX9H//2Q==</field>
 +            <field name="image" type="base64" file="sale/static/img/advance_product_0-image.jpg"/>
          </record>
  
          <record id="base.user_demo" model="res.users">
  
          <menuitem id="base.menu_product" name="Products" parent="base.menu_base_partner" sequence="9"/>
  
 -
 -        <record id="view_shop_form" model="ir.ui.view">
 -            <field name="name">sale.shop</field>
 -            <field name="model">sale.shop</field>
 -            <field name="arch" type="xml">
 -                <form string="Sales Shop" version="7.0">
 -                    <label for="name" class="oe_edit_only"/>
 -                    <h1><field name="name"/></h1>
 -                    <group name="shop">
 -                        <group>
 -                            <field name="payment_default_id"/>
 -                            <field domain="[('type','=','sale')]" required="True" name="pricelist_id" groups="product.group_sale_pricelist"/>
 -                        </group>
 -                        <group>
 -                            <field name="project_id" groups="analytic.group_analytic_accounting"/>
 -                            <field name="company_id" widget="selection" groups="base.group_multi_company"/>
 -                        </group>
 -                    </group>
 -                </form>
 -           </field>
 -        </record>
 -        
 -        <record id="view_shop_tree" model="ir.ui.view">
 -            <field name="name">sale.shop</field>
 -            <field name="model">sale.shop</field>
 -            <field name="arch" type="xml">
 -                <tree string="Sales Shop">
 -                    <field name="name"/>
 -                    <field name="pricelist_id" groups="product.group_sale_pricelist"/>
 -                    <field name="project_id" groups="analytic.group_analytic_accounting"/>
 -                </tree>
 -            </field>
 -        </record>
 -
 -        <record id="action_shop_form" model="ir.actions.act_window">
 -            <field name="name">Shop</field>
 -            <field name="type">ir.actions.act_window</field>
 -            <field name="res_model">sale.shop</field>
 -            <field name="view_type">form</field>
 -            <field name="view_mode">tree,form</field>
 -            <field name="view_id" ref="view_shop_tree"/>
 -            <field name="help" type="html">
 -              <p class="oe_view_nocontent_create">
 -                Click to define a new sale shop.
 -              </p><p>
 -                Each quotation or sales order must be linked to a shop. The
 -                shop also defines the warehouse from which the products will be
 -                delivered for each particular sales.
 -              </p>
 -            </field>
 -        </record>
 -
 -
          <record id="view_sale_order_calendar" model="ir.ui.view">
              <field name="name">sale.order.calendar</field>
              <field name="model">sale.order</field>
@@@ -28,8 -81,8 +28,8 @@@
              <field name="model">sale.order</field>
              <field name="arch" type="xml">
                  <graph string="Sales Orders" type="bar">
 -                    <field name="partner_id"/>
 -                    <field name="amount_total" operator="+"/>
 +                    <field name="partner_id" type="row"/>
 +                    <field name="amount_total" type="measure"/>
                  </graph>
              </field>
          </record>
                          </group>
                          <group>
                              <field name="date_order"/>
 -                            <field name="shop_id" groups="base.group_no_one" on_change="onchange_shop_id(shop_id, context)" widget="selection"/>
                              <field name="client_order_ref"/>
                              <field domain="[('type','=','sale')]" name="pricelist_id" groups="product.group_sale_pricelist" on_change="onchange_pricelist_id(pricelist_id,order_line)"/>
                              <field name="currency_id" invisible="1"/>
                                      <group>
                                          <group>
                                              <field name="product_id"
 -                                                context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
 +                                                context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom}"
                                                  groups="base.group_user"
                                                  on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, False, product_uos_qty, False, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)"/>
                                              <label for="product_uom_qty"/>
                                              <div>
                                                  <field
 -                                                    context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
 +                                                    context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom}"
                                                      name="product_uom_qty" class="oe_inline"
                                                      on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, False, parent.fiscal_position, True, context)"/>
                                                  <field name="product_uom" groups="product.group_uom" class="oe_inline oe_no_button"
                                      <field name="state" invisible="1"/>
                                      <field name="th_weight" invisible="1"/>
                                      <field name="product_id"
 -                                        context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
 +                                        context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom}"
                                          groups="base.group_user" 
                                          on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, False, product_uos_qty, False, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)"/>
                                      <field name="name"/>
                                      <field name="product_uom_qty"
 -                                        context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
 +                                        context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom}"
                                          on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, False, parent.date_order, False, parent.fiscal_position, True, context)"/>
                                      <field name="product_uom"
                                          on_change="product_uom_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, False, parent.date_order, context)"
                          <page string="Other Information" groups="base.group_user">
                              <group>
                                  <group name="sales_person" groups="base.group_user">
 -                                    <field name="user_id"/>
 +                                    <field name="user_id" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'account.group_account_invoice', 'base.group_sale_salesman_all_leads']}"/>
                                      <field groups="base.group_no_one" name="origin"/>
                                  </group>
                                  <group name="sale_pay">
 -                                    <field name="payment_term" widget="selection"/>
 -                                    <field name="fiscal_position" widget="selection"/>
 +                                    <field name="payment_term" options="{'no_create': True}"/>
 +                                    <field name="fiscal_position" options="{'no_create': True}"/>
                                      <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                                  </group>
                                  <group>
              <field name="name">sale.order.form.editable.list</field>
              <field name="model">sale.order</field>
              <field name="inherit_id" ref="sale.view_order_form"/>
 -            <field name="groups_id" eval="[(6, 0, [ref('product.group_uos'), ref('product.group_stock_packaging'), ref('sale.group_mrp_properties')])]"/>
 +            <field name="groups_id" eval="[(4, ref('product.group_uos')), (4, ref('product.group_stock_packaging')), (4, ref('sale.group_mrp_properties'))]"/>
              <field name="arch" type="xml">
                  <xpath expr="//field[@name='order_line']/tree" position="attributes">
                      <attribute name="editable"/>
                      <filter icon="terp-dolar_ok!" string="To Invoice" domain="[('state','=','manual')]" help="Sales Order ready to be invoiced"/>
                      <filter icon="terp-dolar_ok!" string="Done" domain="[('state','=','done')]" help="Sales Order done"/>
                      <separator/>
 -                    <filter string="My Sales Orders" domain="[('user_id','=',uid)]" help="My Sales Orders" icon="terp-personal" name="my_sale_orders_filter"/>
 +                    <filter string="My" domain="[('user_id','=',uid)]" help="My Sales Orders" icon="terp-personal" name="my_sale_orders_filter"/>
-                     <field name="partner_id" filter_domain="[('partner_id', 'child_of', self)]"/>
+                     <field name="partner_id" operator="child_of"/>
                      <field name="user_id"/>
                      <field name="project_id"/>
                      <group expand="0" string="Group By...">
                          <filter string="Customer" icon="terp-personal" domain="[]" context="{'group_by':'partner_id'}"/>
                          <filter string="Salesperson" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
                          <filter string="Status" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
 -                        <filter string="Order Date" icon="terp-go-month" domain="[]" context="{'group_by':'date_order'}"/>
 +                        <filter string="Order Month" icon="terp-go-month" domain="[]" context="{'group_by':'date_order'}"/>
                      </group>
                 </search>
              </field>
              <field name="view_type">form</field>
              <field name="view_mode">tree,form,calendar,graph</field>
              <field name="search_view_id" ref="view_sales_order_filter"/>
 -            <field name="context">{}</field>
 -            <field name="domain">[('state','not in',('draft','sent','cancel'))]</field>
 +            <field name="context">{
 +                    'search_default_my_sale_orders_filter': 1
 +                }
 +            </field>
 +            <field name="domain">[('state', 'not in', ('draft', 'sent', 'cancel'))]</field>
              <field name="help" type="html">
 -              <p class="oe_view_nocontent_create">
 -                Click to create a quotation that can be converted into a sales
 -                order.
 -              </p><p>
 -                OpenERP will help you efficiently handle the complete sales flow:
 -                quotation, sales order, delivery, invoicing and payment.
 -              </p>
 +                <p class="oe_view_nocontent_create">
 +                    Click to create a quotation that can be converted into a sales
 +                    order.
 +                </p><p>
 +                    OpenERP will help you efficiently handle the complete sales flow:
 +                    quotation, sales order, delivery, invoicing and payment.
 +                </p>
              </field>
          </record>
 -        <menuitem action="action_orders" id="menu_sale_order" parent="base.menu_sales" sequence="5" groups="base.group_sale_salesman,base.group_sale_manager"/>
 +
 +        <menuitem action="action_orders" id="menu_sale_order" parent="base.menu_sales" sequence="6" groups="base.group_sale_salesman,base.group_sale_manager"/>
  
          <record id="action_orders_exception" model="ir.actions.act_window">
              <field name="name">Sales in Exception</field>
              <field name="view_type">form</field>
              <field name="view_id" ref="view_quotation_tree"/>
              <field name="view_mode">tree,form,calendar,graph</field>
 -            <field name="context">{}</field>
 +            <field name="context">{'search_default_my_sale_orders_filter': 1}</field>
              <field name="domain">[('state','in',('draft','sent','cancel'))]</field>
              <field name="search_view_id" ref="view_sales_order_filter"/>
              <field name="help" type="html">
          </record>
  
          <menuitem id="menu_sale_quotations"
 -        action="action_quotations" parent="base.menu_sales"
 -        sequence="4"/>
 +                action="action_quotations" parent="base.menu_sales"
 +                sequence="5"/>
  
          <record id="action_order_tree" model="ir.actions.act_window">
              <field name="name">Old Quotations</field>
                      <separator/>
                      <filter string="My Sales Order Lines" icon="terp-personnal" domain="[('salesman_id','=',uid)]" help="Sales Order Lines related to a Sales Order of mine"/>
                      <field name="order_id"/>
-                     <field name="order_partner_id" filter_domain="[('order_partner_id', 'child_of', self)]"/>
+                     <field name="order_partner_id" operator="child_of"/>
                      <field name="product_id"/>
                      <field name="salesman_id"/>
                      <group expand="0" string="Group By...">
                      <separator/>
                      <filter string="My Sales Order Lines" icon="terp-personal" domain="[('salesman_id','=',uid)]" help="My Sales Order Lines"/>
                      <field name="order_id"/>
-                     <field name="order_partner_id" filter_domain="[('order_partner_id', 'child_of', self)]"/>
+                     <field name="order_partner_id" operator="child_of"/>
                      <field name="product_id"/>
                      <field name="salesman_id"/>
                      <group expand="0" string="Group By...">
              <field name="domain">[('invoiced','&lt;&gt;', 1),('state','=','done')]</field>
              <field name="filter" eval="True"/>
          </record>
 -
 -        <act_window
 -            context="{'search_default_product_id': active_id, 'default_product_id': active_id}"
 -            id="action_order_line_product_tree"
 -            name="Sales Order Lines"
 -            res_model="sale.order.line"
 -            src_model="product.product"
 -            groups="base.group_sale_salesman"/>
 -
 +        <record id="action_order_line_product_tree" model="ir.actions.act_window">
 +            <field name="context">{'search_default_product_id': active_id, 'default_product_id': active_id}</field>
 +            <field name="name">Sales Order Lines</field>
 +            <field name="res_model">sale.order.line</field>
 +            <field name="view_id" ref="view_order_line_tree"/>
 +        </record>
 +        <record model="ir.ui.view" id="product_form_view_sale_order_button">
 +            <field name="name">product.product.sale.order</field>
 +            <field name="model">product.product</field>
 +            <field name="inherit_id" ref="product.product_normal_form_view"/>
 +            <field name="arch" type="xml">
 +                <xpath expr="//div[@name='buttons']" position="inside">
 +                    <button string="Sales" name="%(action_order_line_product_tree)d" type="action" groups="base.group_sale_salesman"/>
 +                </xpath>
 +            </field>
 +        </record>
          <menuitem id="base.menu_invoiced" name="Invoicing" parent="base.menu_base_partner" sequence="5"/>
          <menuitem id="menu_invoicing_sales_order_lines" parent="base.menu_invoiced" action="action_order_line_tree2" sequence="10" groups="sale.group_invoice_so_lines"/>
  
 +        <record model="ir.ui.view" id="view_company_inherit_form2">
 +            <field name="name">res.company.form.inherit</field>
 +            <field name="inherit_id" ref="base.view_company_form"/>
 +            <field name="model">res.company</field>
 +            <field name="arch" type="xml">
 +                <xpath expr="//group[@name='account_grp']" position="after">
 +                    <group name="sale_grp" string="Sales">
 +                        <field name="sale_note" nolabel="1" placeholder="Default terms &amp; conditions..."/>
 +                    </group>
 +                </xpath>
 +            </field>
 +        </record>
      </data>
  </openerp>
@@@ -3,37 -3,21 +3,37 @@@
      <data noupdate="1">
      
          <record id="sale.sale_order_1" model="sale.order">
 +            <field name="warehouse_id" ref="stock.warehouse0"/>
              <field name="order_policy">prepaid</field>
          </record>
 -
 +        
 +        <record id="sale.sale_order_2" model="sale.order">
 +            <field name="warehouse_id" ref="stock.warehouse0"/>
 +        </record>
 +        
 +        <record id="sale.sale_order_3" model="sale.order">
 +            <field name="warehouse_id" ref="stock.warehouse0"/>
 +        </record>
 +        
          <record id="sale.sale_order_4" model="sale.order">
 +            <field name="warehouse_id" ref="stock.warehouse0"/>
              <field name="order_policy">prepaid</field>
          </record>
  
          <record id="sale.sale_order_5" model="sale.order">
 +            <field name="warehouse_id" ref="stock.warehouse0"/>
              <field name="order_policy">picking</field>
          </record>
  
          <record id="sale.sale_order_6" model="sale.order">
 +            <field name="warehouse_id" ref="stock.warehouse0"/>
              <field name="order_policy">picking</field>
          </record>
          
 +        <record id="sale.sale_order_8" model="sale.order">
 +            <field name="warehouse_id" ref="stock.warehouse0"/>
 +        </record>
 +        
           <!-- Confirm some Sale Orders-->
          <workflow action="order_confirm" model="sale.order" ref="sale.sale_order_1"/>
          <workflow action="order_confirm" model="sale.order" ref="sale.sale_order_5"/>
               <field name="type">make_to_order</field>
          </record>
  
+         <record id="sale.advance_product_0" model="product.product">
+             <field name="supply_method">produce</field>
+         </record>
          <!-- Run all schedulers -->
          <function model="procurement.order" name="run_scheduler"/>
          
diff --combined addons/stock/stock.py
@@@ -27,7 -27,7 +27,7 @@@ from itertools import groupb
  
  from openerp.osv import fields, osv, orm
  from openerp.tools.translate import _
 -from openerp import netsvc
 +from openerp import workflow
  from openerp import tools
  from openerp.tools import float_compare, DEFAULT_SERVER_DATETIME_FORMAT
  import openerp.addons.decimal_precision as dp
@@@ -49,6 -49,7 +49,6 @@@ class stock_incoterms(osv.osv)
          'active': True,
      }
  
 -stock_incoterms()
  
  class stock_journal(osv.osv):
      _name = "stock.journal"
@@@ -61,6 -62,7 +61,6 @@@
          'user_id': lambda s, c, u, ctx: u
      }
  
 -stock_journal()
  
  #----------------------------------------------------------
  # Stock Location
@@@ -159,10 -161,6 +159,10 @@@ class stock_location(osv.osv)
                         \n* Production: Virtual counterpart location for production operations: this location consumes the raw material and produces finished products
                        """, select = True),
           # temporarily removed, as it's unused: 'allocation_method': fields.selection([('fifo', 'FIFO'), ('lifo', 'LIFO'), ('nearest', 'Nearest')], 'Allocation Method', required=True),
 +
 +        # as discussed on bug 765559, the main purpose of this field is to allow sorting the list of locations
 +        # according to the displayed names, and reversing that sort by clicking on a column. It does not work for
 +        # translated values though - so it needs fixing.
          'complete_name': fields.function(_complete_name, type='char', size=256, string="Location Name",
                              store={'stock.location': (_get_sublocations, ['name', 'location_id'], 10)}),
  
                      continue
          return False
  
 -stock_location()
  
  
  class stock_tracking(osv.osv):
          """
          return self.pool.get('action.traceability').action_traceability(cr,uid,ids,context)
  
 -stock_tracking()
  
  #----------------------------------------------------------
  # Stock Picking
@@@ -631,7 -631,7 +631,7 @@@ class stock_picking(osv.osv)
          return res
  
      def create(self, cr, user, vals, context=None):
 -        if ('name' not in vals) or (vals.get('name')=='/'):
 +        if ('name' not in vals) or (vals.get('name')=='/') or (vals.get('name') == False):
              seq_obj_name =  self._name
              vals['name'] = self.pool.get('ir.sequence').get(cr, user, seq_obj_name)
          new_id = super(stock_picking, self).create(cr, user, vals, context)
              default = {}
          default = default.copy()
          picking_obj = self.browse(cr, uid, id, context=context)
-         move_obj = self.pool.get('stock.move')
          if ('name' not in default) or (picking_obj.name == '/'):
              seq_obj_name = 'stock.picking.' + picking_obj.type
              default['name'] = self.pool.get('ir.sequence').get(cr, uid, seq_obj_name)
          if 'invoice_state' not in default and picking_obj.invoice_state == 'invoiced':
              default['invoice_state'] = '2binvoiced'
          res = super(stock_picking, self).copy(cr, uid, id, default, context)
-         if res:
-             picking_obj = self.browse(cr, uid, res, context=context)
-             for move in picking_obj.move_lines:
-                 move_obj.write(cr, uid, [move.id], {'tracking_id': False, 'prodlot_id': False, 'move_history_ids2': [(6, 0, [])], 'move_history_ids': [(6, 0, [])]})
          return res
  
      def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
          """ Changes state of picking to available if all moves are confirmed.
          @return: True
          """
 -        wf_service = netsvc.LocalService("workflow")
          for pick in self.browse(cr, uid, ids):
              if pick.state == 'draft':
 -                wf_service.trg_validate(uid, 'stock.picking', pick.id, 'button_confirm', cr)
 +                self.signal_button_confirm(cr, uid, [pick.id])
              move_ids = [x.id for x in pick.move_lines if x.state == 'confirmed']
              if not move_ids:
                  raise osv.except_osv(_('Warning!'),_('Not enough stock, unable to reserve the products.'))
          """ Changes state of picking to available if moves are confirmed or waiting.
          @return: True
          """
          for pick in self.browse(cr, uid, ids):
              move_ids = [x.id for x in pick.move_lines if x.state in ['confirmed','waiting']]
              self.pool.get('stock.move').force_assign(cr, uid, move_ids)
 -            wf_service.trg_write(uid, 'stock.picking', pick.id, cr)
 +            workflow.trg_write(uid, 'stock.picking', pick.id, cr)
          return True
  
      def draft_force_assign(self, cr, uid, ids, *args):
          """ Confirms picking directly from draft state.
          @return: True
          """
          for pick in self.browse(cr, uid, ids):
              if not pick.move_lines:
                  raise osv.except_osv(_('Error!'),_('You cannot process picking without stock moves.'))
 -            wf_service.trg_validate(uid, 'stock.picking', pick.id,
 -                'button_confirm', cr)
 +            self.signal_button_confirm(cr, uid, [pick.id])
          return True
  
      def draft_validate(self, cr, uid, ids, context=None):
          """ Validates picking directly from draft state.
          @return: True
          """
 -        wf_service = netsvc.LocalService("workflow")
          self.draft_force_assign(cr, uid, ids)
          for pick in self.browse(cr, uid, ids, context=context):
              move_ids = [x.id for x in pick.move_lines]
              self.pool.get('stock.move').force_assign(cr, uid, move_ids)
 -            wf_service.trg_write(uid, 'stock.picking', pick.id, cr)
 +            workflow.trg_write(uid, 'stock.picking', pick.id, cr)
          return self.action_process(
              cr, uid, ids, context=context)
      def cancel_assign(self, cr, uid, ids, *args):
          """ Cancels picking and moves.
          @return: True
          """
          for pick in self.browse(cr, uid, ids):
              move_ids = [x.id for x in pick.move_lines]
              self.pool.get('stock.move').cancel_assign(cr, uid, move_ids)
 -            wf_service.trg_write(uid, 'stock.picking', pick.id, cr)
 +            workflow.trg_write(uid, 'stock.picking', pick.id, cr)
          return True
  
      def action_assign_wkf(self, cr, uid, ids, context=None):
          currency_obj = self.pool.get('res.currency')
          uom_obj = self.pool.get('product.uom')
          sequence_obj = self.pool.get('ir.sequence')
 -        wf_service = netsvc.LocalService("workflow")
          for pick in self.browse(cr, uid, ids, context=context):
              new_picking = None
              complete, too_many, too_few = [], [], []
  
              # At first we confirm the new picking (if necessary)
              if new_picking:
 -                wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_confirm', cr)
 +                self.signal_button_confirm(cr, uid, [new_picking])
                  # Then we finish the good picking
                  self.write(cr, uid, [pick.id], {'backorder_id': new_picking})
                  self.action_move(cr, uid, [new_picking], context=context)
 -                wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_done', cr)
 -                wf_service.trg_write(uid, 'stock.picking', pick.id, cr)
 +                self.signal_button_done(cr, uid, [new_picking])
 +                workflow.trg_write(uid, 'stock.picking', pick.id, cr)
                  delivered_pack_id = pick.id
                  back_order_name = self.browse(cr, uid, delivered_pack_id, context=context).name
                  self.message_post(cr, uid, new_picking, body=_("Back order <em>%s</em> has been <b>created</b>.") % (back_order_name), context=context)
              else:
                  self.action_move(cr, uid, [pick.id], context=context)
 -                wf_service.trg_validate(uid, 'stock.picking', pick.id, 'button_done', cr)
 +                self.signal_button_done(cr, uid, [pick.id])
                  delivered_pack_id = pick.id
  
              delivered_pack = self.browse(cr, uid, delivered_pack_id, context=context)
@@@ -1505,6 -1507,7 +1500,6 @@@ class stock_production_lot(osv.osv)
          default.update(date=time.strftime('%Y-%m-%d %H:%M:%S'), move_ids=[])
          return super(stock_production_lot, self).copy(cr, uid, id, default=default, context=context)
  
 -stock_production_lot()
  
  class stock_production_lot_revision(osv.osv):
      _name = 'stock.production.lot.revision'
          'date': fields.date.context_today,
      }
  
 -stock_production_lot_revision()
  
  # ----------------------------------------------------
  # Move
@@@ -1797,12 -1801,15 +1792,15 @@@ class stock_move(osv.osv)
                                               _('Quantities, Units of Measure, Products and Locations cannot be modified on stock moves that have already been processed (except by the Administrator).'))
          return  super(stock_move, self).write(cr, uid, ids, vals, context=context)
  
-     def copy(self, cr, uid, id, default=None, context=None):
+     def copy_data(self, cr, uid, id, default=None, context=None):
          if default is None:
              default = {}
          default = default.copy()
-         default.update({'move_history_ids2': [], 'move_history_ids': []})
-         return super(stock_move, self).copy(cr, uid, id, default, context=context)
+         default.setdefault('tracking_id', False)
+         default.setdefault('prodlot_id', False)
+         default.setdefault('move_history_ids', [])
+         default.setdefault('move_history_ids2', [])
+         return super(stock_move, self).copy_data(cr, uid, id, default, context=context)
  
      def _auto_init(self, cursor, context=None):
          res = super(stock_move, self)._auto_init(cursor, context=context)
          res_obj = self.pool.get('res.company')
          location_obj = self.pool.get('stock.location')
          move_obj = self.pool.get('stock.move')
 -        wf_service = netsvc.LocalService("workflow")
          new_moves = []
          if context is None:
              context = {}
                      })
                      new_moves.append(self.browse(cr, uid, [new_id])[0])
                  if pickid:
 -                    wf_service.trg_validate(uid, 'stock.picking', pickid, 'button_confirm', cr)
 +                    self.pool.get('stock.picking').signal_button_confirm(cr, uid, [pickid])
          if new_moves:
              new_moves += self.create_chained_picking(cr, uid, new_moves, context)
          return new_moves
          @return: True
          """
          self.write(cr, uid, ids, {'state': 'assigned'})
 -        wf_service = netsvc.LocalService('workflow')
          for move in self.browse(cr, uid, ids, context):
              if move.picking_id:
 -                wf_service.trg_write(uid, 'stock.picking', move.picking_id.id, cr)
 +                workflow.trg_write(uid, 'stock.picking', move.picking_id.id, cr)
          return True
  
      def cancel_assign(self, cr, uid, ids, context=None):
          # fix for bug lp:707031
          # called write of related picking because changing move availability does
          # not trigger workflow of picking in order to change the state of picking
 -        wf_service = netsvc.LocalService('workflow')
          for move in self.browse(cr, uid, ids, context):
              if move.picking_id:
 -                wf_service.trg_write(uid, 'stock.picking', move.picking_id.id, cr)
 +                workflow.trg_write(uid, 'stock.picking', move.picking_id.id, cr)
          return True
  
      #
  
          if count:
              for pick_id in pickings:
 -                wf_service = netsvc.LocalService("workflow")
 -                wf_service.trg_write(uid, 'stock.picking', pick_id, cr)
 +                workflow.trg_write(uid, 'stock.picking', pick_id, cr)
          return count
  
      def setlast_tracking(self, cr, uid, ids, context=None):
              if move.move_dest_id and move.move_dest_id.state == 'waiting':
                  self.write(cr, uid, [move.move_dest_id.id], {'state': 'confirmed'}, context=context)
                  if context.get('call_unlink',False) and move.move_dest_id.picking_id:
 -                    wf_service = netsvc.LocalService("workflow")
 -                    wf_service.trg_write(uid, 'stock.picking', move.move_dest_id.picking_id.id, cr)
 +                    workflow.trg_write(uid, 'stock.picking', move.move_dest_id.picking_id.id, cr)
          self.write(cr, uid, ids, {'state': 'cancel', 'move_dest_id': False}, context=context)
          if not context.get('call_unlink',False):
              for pick in self.pool.get('stock.picking').browse(cr, uid, list(pickings), context=context):
                  if all(move.state == 'cancel' for move in pick.move_lines):
                      self.pool.get('stock.picking').write(cr, uid, [pick.id], {'state': 'cancel'}, context=context)
  
 -        wf_service = netsvc.LocalService("workflow")
          for id in ids:
 -            wf_service.trg_trigger(uid, 'stock.move', id, cr)
 +            workflow.trg_trigger(uid, 'stock.move', id, cr)
          return True
  
      def _get_accounting_data_for_valuation(self, cr, uid, move, context=None):
          """
          picking_ids = []
          move_ids = []
 -        wf_service = netsvc.LocalService("workflow")
          if context is None:
              context = {}
  
                      if move.move_dest_id.state in ('waiting', 'confirmed'):
                          self.force_assign(cr, uid, [move.move_dest_id.id], context=context)
                          if move.move_dest_id.picking_id:
 -                            wf_service.trg_write(uid, 'stock.picking', move.move_dest_id.picking_id.id, cr)
 +                            workflow.trg_write(uid, 'stock.picking', move.move_dest_id.picking_id.id, cr)
                          if move.move_dest_id.auto_validate:
                              self.action_done(cr, uid, [move.move_dest_id.id], context=context)
  
  
          self.write(cr, uid, move_ids, {'state': 'done', 'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)}, context=context)
          for id in move_ids:
 -             wf_service.trg_trigger(uid, 'stock.move', id, cr)
 +             workflow.trg_trigger(uid, 'stock.move', id, cr)
  
          for pick_id in picking_ids:
 -            wf_service.trg_write(uid, 'stock.picking', pick_id, cr)
 +            workflow.trg_write(uid, 'stock.picking', pick_id, cr)
  
          return True
  
          product_obj = self.pool.get('product.product')
          currency_obj = self.pool.get('res.currency')
          uom_obj = self.pool.get('product.uom')
 -        wf_service = netsvc.LocalService("workflow")
  
          if context is None:
              context = {}
                  res = cr.fetchall()
                  if len(res) == len(move.picking_id.move_lines):
                      picking_obj.action_move(cr, uid, [move.picking_id.id])
 -                    wf_service.trg_validate(uid, 'stock.picking', move.picking_id.id, 'button_done', cr)
 +                    picking_obj.signal_button_done(cr, uid, [move.picking_id.id])
  
          return [move.id for move in complete]
  
 -stock_move()
  
  class stock_inventory(osv.osv):
      _name = "stock.inventory"
              self.write(cr, uid, [inv.id], {'state': 'cancel'}, context=context)
          return True
  
 -stock_inventory()
  
  class stock_inventory_line(osv.osv):
      _name = "stock.inventory.line"
          result = {'product_qty': amount, 'product_uom': uom, 'prod_lot_id': False}
          return {'value': result}
  
 -stock_inventory_line()
  
  #----------------------------------------------------------
  # Stock Warehouse
@@@ -2984,6 -3002,7 +2982,6 @@@ class stock_warehouse(osv.osv)
          'lot_output_id': _default_lot_output_id,
      }
  
 -stock_warehouse()
  
  #----------------------------------------------------------
  # "Empty" Classes that are used to vary from the original stock.picking  (that are dedicated to the internal pickings)
@@@ -3009,25 -3028,15 +3007,25 @@@ class stock_picking_in(osv.osv)
          #override in order to redirect the check of acces rules on the stock.picking object
          return self.pool.get('stock.picking').check_access_rule(cr, uid, ids, operation, context=context)
  
 -    def _workflow_trigger(self, cr, uid, ids, trigger, context=None):
 -        #override in order to trigger the workflow of stock.picking at the end of create, write and unlink operation
 -        #instead of it's own workflow (which is not existing)
 -        return self.pool.get('stock.picking')._workflow_trigger(cr, uid, ids, trigger, context=context)
 +    def create_workflow(self, cr, uid, ids, context=None):
 +        # overridden in order to trigger the workflow of stock.picking at the end of create,
 +        # write and unlink operation instead of its own workflow (which is not existing)
 +        return self.pool.get('stock.picking').create_workflow(cr, uid, ids, context=context)
 +
 +    def delete_workflow(self, cr, uid, ids, context=None):
 +        # overridden in order to trigger the workflow of stock.picking at the end of create,
 +        # write and unlink operation instead of its own workflow (which is not existing)
 +        return self.pool.get('stock.picking').delete_workflow(cr, uid, ids, context=context)
  
 -    def _workflow_signal(self, cr, uid, ids, signal, context=None):
 -        #override in order to fire the workflow signal on given stock.picking workflow instance
 -        #instead of it's own workflow (which is not existing)
 -        return self.pool.get('stock.picking')._workflow_signal(cr, uid, ids, signal, context=context)
 +    def step_workflow(self, cr, uid, ids, context=None):
 +        # overridden in order to trigger the workflow of stock.picking at the end of create,
 +        # write and unlink operation instead of its own workflow (which is not existing)
 +        return self.pool.get('stock.picking').step_workflow(cr, uid, ids, context=context)
 +
 +    def signal_workflow(self, cr, uid, ids, signal, context=None):
 +        # overridden in order to fire the workflow signal on given stock.picking workflow instance
 +        # instead of its own workflow (which is not existing)
 +        return self.pool.get('stock.picking').signal_workflow(cr, uid, ids, signal, context=context)
  
      def message_post(self, *args, **kwargs):
          """Post the message on stock.picking to be able to see it in the form view when using the chatter"""
@@@ -3089,25 -3098,15 +3087,25 @@@ class stock_picking_out(osv.osv)
          #override in order to redirect the check of acces rules on the stock.picking object
          return self.pool.get('stock.picking').check_access_rule(cr, uid, ids, operation, context=context)
  
 -    def _workflow_trigger(self, cr, uid, ids, trigger, context=None):
 -        #override in order to trigger the workflow of stock.picking at the end of create, write and unlink operation
 -        #instead of it's own workflow (which is not existing)
 -        return self.pool.get('stock.picking')._workflow_trigger(cr, uid, ids, trigger, context=context)
 -
 -    def _workflow_signal(self, cr, uid, ids, signal, context=None):
 -        #override in order to fire the workflow signal on given stock.picking workflow instance
 -        #instead of it's own workflow (which is not existing)
 -        return self.pool.get('stock.picking')._workflow_signal(cr, uid, ids, signal, context=context)
 +    def create_workflow(self, cr, uid, ids, context=None):
 +        # overridden in order to trigger the workflow of stock.picking at the end of create,
 +        # write and unlink operation instead of its own workflow (which is not existing)
 +        return self.pool.get('stock.picking').create_workflow(cr, uid, ids, context=context)
 +
 +    def delete_workflow(self, cr, uid, ids, context=None):
 +        # overridden in order to trigger the workflow of stock.picking at the end of create,
 +        # write and unlink operation instead of its own workflow (which is not existing)
 +        return self.pool.get('stock.picking').delete_workflow(cr, uid, ids, context=context)
 +
 +    def step_workflow(self, cr, uid, ids, context=None):
 +        # overridden in order to trigger the workflow of stock.picking at the end of create,
 +        # write and unlink operation instead of its own workflow (which is not existing)
 +        return self.pool.get('stock.picking').step_workflow(cr, uid, ids, context=context)
 +
 +    def signal_workflow(self, cr, uid, ids, signal, context=None):
 +        # overridden in order to fire the workflow signal on given stock.picking workflow instance
 +        # instead of its own workflow (which is not existing)
 +        return self.pool.get('stock.picking').signal_workflow(cr, uid, ids, signal, context=context)
  
      def message_post(self, *args, **kwargs):
          """Post the message on stock.picking to be able to see it in the form view when using the chatter"""
@@@ -28,8 -28,8 +28,8 @@@ class stock_location_product(osv.osv_me
      _columns = {
          'from_date': fields.datetime('From'), 
          'to_date': fields.datetime('To'),
-         'type': fields.selection([('inventory','Analyse Current Inventory'),
-             ('period','Analyse a Period')], 'Analyse Type', required=True), 
+         'type': fields.selection([('inventory','Analyze current inventory'),
+             ('period','Analyze period')], 'Analysis Type', required=True), 
      }
  
      def action_open_window(self, cr, uid, ids, context=None):
@@@ -57,5 -57,6 +57,5 @@@
                  'domain': [('type', '<>', 'service')],
              }
  
 -stock_location_product()
  
  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: