[MERGE] accounts* modules: forward port of revision 9033 of addons v7 that was passing 'account_period_prefer_normal=True' in the context in each and every call to account_period.find(). The behaviour is modified in order to search only on normal periods by default

bzr revid: qdp-launchpad@openerp.com-20130418094147-q2ks4w47sn4fxdv2
bzr revid: qdp-launchpad@openerp.com-20130418103907-0qom5yfcq8osnovp
This commit is contained in:
Quentin (OpenERP) 2013-04-18 12:39:07 +02:00
commit 429ef87172
15 changed files with 71 additions and 37 deletions

View File

@ -1001,8 +1001,7 @@ class account_period(osv.osv):
def find(self, cr, uid, dt=None, context=None): def find(self, cr, uid, dt=None, context=None):
if context is None: context = {} if context is None: context = {}
if not dt: if not dt:
dt = fields.date.context_today(self,cr,uid,context=context) dt = fields.date.context_today(self, cr, uid, context=context)
#CHECKME: shouldn't we check the state of the period?
args = [('date_start', '<=' ,dt), ('date_stop', '>=', dt)] args = [('date_start', '<=' ,dt), ('date_stop', '>=', dt)]
if context.get('company_id', False): if context.get('company_id', False):
args.append(('company_id', '=', context['company_id'])) args.append(('company_id', '=', context['company_id']))
@ -1010,7 +1009,7 @@ class account_period(osv.osv):
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
args.append(('company_id', '=', company_id)) args.append(('company_id', '=', company_id))
result = [] result = []
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 # 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) result = self.search(cr, uid, args + [('special', '=', False)], context=context)
if not result: if not result:
@ -1214,7 +1213,7 @@ class account_move(osv.osv):
return res return res
def _get_period(self, cr, uid, context=None): 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) period_ids = self.pool.get('account.period').find(cr, uid, context=ctx)
return period_ids[0] return period_ids[0]
@ -1786,7 +1785,7 @@ class account_tax_code(osv.osv):
if context.get('period_id', False): if context.get('period_id', False):
period_id = context['period_id'] period_id = context['period_id']
else: else:
period_id = self.pool.get('account.period').find(cr, uid) period_id = self.pool.get('account.period').find(cr, uid, context=context)
if not period_id: if not period_id:
return dict.fromkeys(ids, 0.0) return dict.fromkeys(ids, 0.0)
period_id = period_id[0] period_id = period_id[0]

View File

@ -61,7 +61,7 @@ class account_bank_statement(osv.osv):
return res return res
def _get_period(self, cr, uid, context=None): def _get_period(self, cr, uid, context=None):
periods = self.pool.get('account.period').find(cr, uid,context=context) periods = self.pool.get('account.period').find(cr, uid, context=context)
if periods: if periods:
return periods[0] return periods[0]
return False return False

View File

@ -985,8 +985,7 @@ class account_invoice(osv.osv):
'narration':inv.comment 'narration':inv.comment
} }
period_id = inv.period_id and inv.period_id.id or False period_id = inv.period_id and inv.period_id.id or False
ctx.update(company_id=inv.company_id.id, ctx.update(company_id=inv.company_id.id)
account_period_prefer_normal=True)
if not period_id: if not period_id:
period_ids = period_obj.find(cr, uid, inv.date_invoice, context=ctx) period_ids = period_obj.find(cr, uid, inv.date_invoice, context=ctx)
period_id = period_ids and period_ids[0] or False period_id = period_ids and period_ids[0] or False

View File

@ -986,8 +986,7 @@ class account_move_line(osv.osv):
if context is None: if context is None:
context = {} context = {}
period_pool = self.pool.get('account.period') period_pool = self.pool.get('account.period')
ctx = dict(context, account_period_prefer_normal=True) pids = period_pool.find(cr, user, date, context=context)
pids = period_pool.find(cr, user, date, context=ctx)
if pids: if pids:
res.update({ res.update({
'period_id':pids[0] 'period_id':pids[0]

View File

@ -23,10 +23,16 @@ import datetime
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
import logging import logging
from operator import itemgetter from operator import itemgetter
from os.path import join as opj
import time import time
import urllib2
import urlparse
from openerp import tools try:
import simplejson as json
except ImportError:
import json # noqa
from openerp.release import serie
from openerp.tools.translate import _ from openerp.tools.translate import _
from openerp.osv import fields, osv from openerp.osv import fields, osv
@ -38,13 +44,28 @@ class account_installer(osv.osv_memory):
def _get_charts(self, cr, uid, context=None): def _get_charts(self, cr, uid, context=None):
modules = self.pool.get('ir.module.module') modules = self.pool.get('ir.module.module')
# try get the list on apps server
try:
apps_server = self.pool.get('ir.config_parameter').get_param(cr, uid, 'apps.server', 'https://apps.openerp.com')
up = urlparse.urlparse(apps_server)
url = '{0.scheme}://{0.netloc}/apps/charts?serie={1}'.format(up, serie)
j = urllib2.urlopen(url, timeout=3).read()
apps_charts = json.loads(j)
charts = dict(apps_charts)
except Exception:
charts = dict()
# Looking for the module with the 'Account Charts' category # Looking for the module with the 'Account Charts' category
category_name, category_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'module_category_localization_account_charts') category_name, category_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'module_category_localization_account_charts')
ids = modules.search(cr, uid, [('category_id', '=', category_id)], context=context) ids = modules.search(cr, uid, [('category_id', '=', category_id)], context=context)
charts = list( if ids:
sorted(((m.name, m.shortdesc) charts.update((m.name, m.shortdesc) for m in modules.browse(cr, uid, ids, context=context))
for m in modules.browse(cr, uid, ids, context=context)),
key=itemgetter(1))) charts = sorted(charts.items(), key=itemgetter(1))
charts.insert(0, ('configurable', _('Custom'))) charts.insert(0, ('configurable', _('Custom')))
return charts return charts
@ -57,9 +78,9 @@ class account_installer(osv.osv_memory):
"country."), "country."),
'date_start': fields.date('Start Date', required=True), 'date_start': fields.date('Start Date', required=True),
'date_stop': fields.date('End Date', required=True), 'date_stop': fields.date('End Date', required=True),
'period': fields.selection([('month', 'Monthly'), ('3months','3 Monthly')], 'Periods', required=True), 'period': fields.selection([('month', 'Monthly'), ('3months', '3 Monthly')], 'Periods', required=True),
'company_id': fields.many2one('res.company', 'Company', required=True), 'company_id': fields.many2one('res.company', 'Company', required=True),
'has_default_company' : fields.boolean('Has Default Company', readonly=True), 'has_default_company': fields.boolean('Has Default Company', readonly=True),
} }
def _default_company(self, cr, uid, context=None): def _default_company(self, cr, uid, context=None):
@ -78,30 +99,29 @@ class account_installer(osv.osv_memory):
'has_default_company': _default_has_default_company, 'has_default_company': _default_has_default_company,
'charts': 'configurable' 'charts': 'configurable'
} }
def get_unconfigured_cmp(self, cr, uid, context=None): def get_unconfigured_cmp(self, cr, uid, context=None):
""" get the list of companies that have not been configured yet """ get the list of companies that have not been configured yet
but don't care about the demo chart of accounts """ but don't care about the demo chart of accounts """
cmp_select = []
company_ids = self.pool.get('res.company').search(cr, uid, [], context=context) company_ids = self.pool.get('res.company').search(cr, uid, [], context=context)
cr.execute("SELECT company_id FROM account_account WHERE active = 't' AND account_account.parent_id IS NULL AND name != %s", ("Chart For Automated Tests",)) cr.execute("SELECT company_id FROM account_account WHERE active = 't' AND account_account.parent_id IS NULL AND name != %s", ("Chart For Automated Tests",))
configured_cmp = [r[0] for r in cr.fetchall()] configured_cmp = [r[0] for r in cr.fetchall()]
return list(set(company_ids)-set(configured_cmp)) return list(set(company_ids)-set(configured_cmp))
def check_unconfigured_cmp(self, cr, uid, context=None): def check_unconfigured_cmp(self, cr, uid, context=None):
""" check if there are still unconfigured companies """ """ check if there are still unconfigured companies """
if not self.get_unconfigured_cmp(cr, uid, context=context): if not self.get_unconfigured_cmp(cr, uid, context=context):
raise osv.except_osv(_('No unconfigured company !'), _("There is currently no company without chart of account. The wizard will therefore not be executed.")) raise osv.except_osv(_('No unconfigured company !'), _("There is currently no company without chart of account. The wizard will therefore not be executed."))
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
if context is None:context = {} if context is None: context = {}
res = super(account_installer, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False) res = super(account_installer, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False)
cmp_select = [] cmp_select = []
# display in the widget selection only the companies that haven't been configured yet # display in the widget selection only the companies that haven't been configured yet
unconfigured_cmp = self.get_unconfigured_cmp(cr, uid, context=context) unconfigured_cmp = self.get_unconfigured_cmp(cr, uid, context=context)
for field in res['fields']: for field in res['fields']:
if field == 'company_id': if field == 'company_id':
res['fields'][field]['domain'] = [('id','in',unconfigured_cmp)] res['fields'][field]['domain'] = [('id', 'in', unconfigured_cmp)]
res['fields'][field]['selection'] = [('', '')] res['fields'][field]['selection'] = [('', '')]
if unconfigured_cmp: if unconfigured_cmp:
cmp_select = [(line.id, line.name) for line in self.pool.get('res.company').browse(cr, uid, unconfigured_cmp)] cmp_select = [(line.id, line.name) for line in self.pool.get('res.company').browse(cr, uid, unconfigured_cmp)]
@ -117,7 +137,7 @@ class account_installer(osv.osv_memory):
def execute(self, cr, uid, ids, context=None): def execute(self, cr, uid, ids, context=None):
self.execute_simple(cr, uid, ids, context) self.execute_simple(cr, uid, ids, context)
super(account_installer, self).execute(cr, uid, ids, context=context) return super(account_installer, self).execute(cr, uid, ids, context=context)
def execute_simple(self, cr, uid, ids, context=None): def execute_simple(self, cr, uid, ids, context=None):
if context is None: if context is None:
@ -129,8 +149,8 @@ class account_installer(osv.osv_memory):
if not f_ids: if not f_ids:
name = code = res['date_start'][:4] name = code = res['date_start'][:4]
if int(name) != int(res['date_stop'][:4]): if int(name) != int(res['date_stop'][:4]):
name = res['date_start'][:4] +'-'+ res['date_stop'][:4] name = res['date_start'][:4] + '-' + res['date_stop'][:4]
code = res['date_start'][2:4] +'-'+ res['date_stop'][2:4] code = res['date_start'][2:4] + '-' + res['date_stop'][2:4]
vals = { vals = {
'name': name, 'name': name,
'code': code, 'code': code,
@ -150,7 +170,7 @@ class account_installer(osv.osv_memory):
chart = self.read(cr, uid, ids, ['charts'], chart = self.read(cr, uid, ids, ['charts'],
context=context)[0]['charts'] context=context)[0]['charts']
_logger.debug('Installing chart of accounts %s', chart) _logger.debug('Installing chart of accounts %s', chart)
return modules | set([chart]) return (modules | set([chart])) - set(['has_default_company', 'configurable'])
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -81,7 +81,7 @@ class account_entries_report(osv.osv):
period_obj = self.pool.get('account.period') period_obj = self.pool.get('account.period')
for arg in args: for arg in args:
if arg[0] == 'period_id' and arg[2] == 'current_period': if arg[0] == 'period_id' and arg[2] == 'current_period':
current_period = period_obj.find(cr, uid)[0] current_period = period_obj.find(cr, uid, context=context)[0]
args.append(['period_id','in',[current_period]]) args.append(['period_id','in',[current_period]])
break break
elif arg[0] == 'period_id' and arg[2] == 'current_year': elif arg[0] == 'period_id' and arg[2] == 'current_year':
@ -100,7 +100,7 @@ class account_entries_report(osv.osv):
fiscalyear_obj = self.pool.get('account.fiscalyear') fiscalyear_obj = self.pool.get('account.fiscalyear')
period_obj = self.pool.get('account.period') period_obj = self.pool.get('account.period')
if context.get('period', False) == 'current_period': if context.get('period', False) == 'current_period':
current_period = period_obj.find(cr, uid)[0] current_period = period_obj.find(cr, uid, context=context)[0]
domain.append(['period_id','in',[current_period]]) domain.append(['period_id','in',[current_period]])
elif context.get('year', False) == 'current_year': elif context.get('year', False) == 'current_year':
current_year = fiscalyear_obj.find(cr, uid) current_year = fiscalyear_obj.find(cr, uid)

View File

@ -148,7 +148,6 @@ class account_move_line_reconcile_writeoff(osv.osv_memory):
context['analytic_id'] = data['analytic_id'][0] context['analytic_id'] = data['analytic_id'][0]
if context['date_p']: if context['date_p']:
date = context['date_p'] date = context['date_p']
ids = period_obj.find(cr, uid, dt=date, context=context) ids = period_obj.find(cr, uid, dt=date, context=context)
if ids: if ids:
period_id = ids[0] period_id = ids[0]

View File

@ -38,7 +38,7 @@ class account_tax_chart(osv.osv_memory):
def _get_period(self, cr, uid, context=None): def _get_period(self, cr, uid, context=None):
"""Return default period value""" """Return default period value"""
period_ids = self.pool.get('account.period').find(cr, uid) period_ids = self.pool.get('account.period').find(cr, uid, context=context)
return period_ids and period_ids[0] or False return period_ids and period_ids[0] or False
def account_tax_chart_open_window(self, cr, uid, ids, context=None): def account_tax_chart_open_window(self, cr, uid, ids, context=None):

View File

@ -82,7 +82,7 @@ class account_asset_asset(osv.osv):
return super(account_asset_asset, self).unlink(cr, uid, ids, context=context) return super(account_asset_asset, self).unlink(cr, uid, ids, context=context)
def _get_period(self, cr, uid, context=None): def _get_period(self, cr, uid, context=None):
periods = self.pool.get('account.period').find(cr, uid) periods = self.pool.get('account.period').find(cr, uid, context=context)
if periods: if periods:
return periods[0] return periods[0]
else: else:

View File

@ -30,7 +30,7 @@ class asset_depreciation_confirmation_wizard(osv.osv_memory):
} }
def _get_period(self, cr, uid, context=None): def _get_period(self, cr, uid, context=None):
periods = self.pool.get('account.period').find(cr, uid) periods = self.pool.get('account.period').find(cr, uid, context=context)
if periods: if periods:
return periods[0] return periods[0]
return False return False

View File

@ -84,7 +84,7 @@ class account_voucher(osv.osv):
if context is None: context = {} if context is None: context = {}
if context.get('period_id', False): if context.get('period_id', False):
return context.get('period_id') return context.get('period_id')
periods = self.pool.get('account.period').find(cr, uid) periods = self.pool.get('account.period').find(cr, uid, context=context)
return periods and periods[0] or False return periods and periods[0] or False
def _make_journal_search(self, cr, uid, ttype, context=None): def _make_journal_search(self, cr, uid, ttype, context=None):

View File

@ -200,6 +200,9 @@ class res_users(osv.Model):
'partner_id': partner.id, 'partner_id': partner.id,
'email': values.get('email') or values.get('login'), 'email': values.get('email') or values.get('login'),
}) })
if partner.company_id:
values['company_id'] = partner.company_id.id
values['company_ids'] = [(6,0,[partner.company_id.id])]
self._signup_create_user(cr, uid, values, context=context) self._signup_create_user(cr, uid, values, context=context)
else: else:
# no token, sign up an external user # no token, sign up an external user

View File

@ -1053,6 +1053,14 @@ class crm_lead(base_stage, format_address, osv.osv):
message = _("%s a call for %s.%s") % (prefix, phonecall.date, suffix) message = _("%s a call for %s.%s") % (prefix, phonecall.date, suffix)
return self.message_post(cr, uid, ids, body=message, context=context) return self.message_post(cr, uid, ids, body=message, context=context)
def log_meeting(self, cr, uid, ids, meeting_subject, meeting_date, duration, context=None):
if not duration:
duration = _('unknown')
else:
duration = str(duration)
message = _("Meeting scheduled at '%s'<br> Subject: %s <br> Duration: %s hour(s)") % (meeting_date, meeting_subject, duration)
return self.message_post(cr, uid, ids, body=message, context=context)
def onchange_state(self, cr, uid, ids, state_id, context=None): def onchange_state(self, cr, uid, ids, state_id, context=None):
if state_id: if state_id:
country_id=self.pool.get('res.country.state').browse(cr, uid, state_id, context).country_id.id country_id=self.pool.get('res.country.state').browse(cr, uid, state_id, context).country_id.id

View File

@ -34,6 +34,13 @@ class crm_meeting(osv.Model):
'opportunity_id': fields.many2one ('crm.lead', 'Opportunity', domain="[('type', '=', 'opportunity')]"), 'opportunity_id': fields.many2one ('crm.lead', 'Opportunity', domain="[('type', '=', 'opportunity')]"),
} }
def create(self, cr, uid, vals, context=None):
res = super(crm_meeting, self).create(cr, uid, vals, context=context)
obj = self.browse(cr, uid, res, context=context)
if obj.opportunity_id:
self.pool.get('crm.lead').log_meeting(cr, uid, [obj.opportunity_id.id], obj.name, obj.date, obj.duration, context=context)
return res
class calendar_attendee(osv.osv): class calendar_attendee(osv.osv):
""" Calendar Attendee """ """ Calendar Attendee """

View File

@ -335,7 +335,7 @@
<field name="type">ir.actions.act_window</field> <field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order</field> <field name="res_model">purchase.order</field>
<field name="context">{}</field> <field name="context">{}</field>
<field name="domain">[('state','in',('draft','sent','cancel'))]</field> <field name="domain">[('state','in',('draft','sent','cancel', 'confirmed'))]</field>
<field name="view_mode">tree,form,graph,calendar</field> <field name="view_mode">tree,form,graph,calendar</field>
<field name="search_view_id" ref="view_purchase_order_filter"/> <field name="search_view_id" ref="view_purchase_order_filter"/>
<field name="help" type="html"> <field name="help" type="html">