From 910b26f28cdc6655f8a377090679a56882c7e87d Mon Sep 17 00:00:00 2001 From: "Daniel Watkins (credativ)" Date: Thu, 9 Sep 2010 14:17:50 +0100 Subject: [PATCH 001/225] Get the scheduler to actually run rules with time delays. bzr revid: daniel.watkins@credativ.co.uk-20100909131750-ntafsguyput7r4xw --- addons/base_action_rule/base_action_rule.py | 81 +++++++++++---------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index ff6321e599f..16a628d9529 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -113,6 +113,7 @@ the rule to mark CC(mail to any other person defined in actions)."), 'filter_id':fields.many2one('ir.filters', 'Filter', required=False), 'act_email_from' : fields.char('Email From', size=64, required=False, help="Use a python expression to specify the right field on which one than we will use for the 'From' field of the header"), + 'last_run': fields.datetime('Last Run', readonly=1), } _defaults = { @@ -204,8 +205,48 @@ the rule to mark CC(mail to any other person defined in actions)."), """ rule_pool = self.pool.get('base.action.rule') rule_ids = rule_pool.search(cr, uid, [], context=context) - return self._register_hook(cr, uid, rule_ids, context=context) - + self._register_hook(cr, uid, rule_ids, context=context) + + rules = self.browse(cr, uid, rule_ids, context=context) + for rule in rules: + print "RULE: %s" % (rule,) + print " %s" % (rule.last_run,) + model = rule.model_id.model + model_pool = self.pool.get(model) + last_run = False + if rule.last_run: + last_run = datetime.strptime(rule.last_run[:19], '%Y-%m-%d %H:%M:%S') + now = datetime.now() + for obj_id in model_pool.search(cr, uid, [], context=context): + print " OBJ: %s" % (obj_id,) + obj = model_pool.browse(cr, uid, obj_id, context=context) + # Calculate when the action should next occur for this object + base = False + if rule.trg_date_type=='create' and hasattr(obj, 'create_date'): + base = datetime.strptime(obj.create_date[:19], '%Y-%m-%d %H:%M:%S') + elif rule.trg_date_type=='action_last' and hasattr(obj, 'create_date'): + if hasattr(obj, 'date_action_last') and obj.date_action_last: + base = datetime.strptime(obj.date_action_last, '%Y-%m-%d %H:%M:%S') + else: + base = datetime.strptime(obj.create_date[:19], '%Y-%m-%d %H:%M:%S') + elif rule.trg_date_type=='deadline' and hasattr(obj, 'date_deadline') \ + and obj.date_deadline: + base = datetime.strptime(obj.date_deadline, '%Y-%m-%d %H:%M:%S') + elif rule.trg_date_type=='date' and hasattr(obj, 'date') and obj.date: + base = datetime.strptime(obj.date, '%Y-%m-%d %H:%M:%S') + if base: + fnct = { + 'minutes': lambda interval: timedelta(minutes=interval), + 'day': lambda interval: timedelta(days=interval), + 'hour': lambda interval: timedelta(hours=interval), + 'month': lambda interval: timedelta(months=interval), + } + d = base + fnct[rule.trg_date_range_type](rule.trg_date_range) + print " D: %s" % (d,) + if (not last_run or (last_run <= d < now)): + print " RUNNING" + self._action(cr, uid, [rule.id], [obj], context=context) + rule_pool.write(cr, uid, [rule.id], {'last_run': now}, context=context) def format_body(self, body): """ Foramat Action rule's body @@ -377,7 +418,6 @@ the rule to mark CC(mail to any other person defined in actions)."), if context is None: context = {} - context.update({'action': True}) if not scrit: scrit = [] @@ -389,41 +429,6 @@ the rule to mark CC(mail to any other person defined in actions)."), if not ok: continue - base = False - if action.trg_date_type=='create' and hasattr(obj, 'create_date'): - base = datetime.strptime(obj.create_date[:19], '%Y-%m-%d %H:%M:%S') - elif action.trg_date_type=='action_last' and hasattr(obj, 'create_date'): - if hasattr(obj, 'date_action_last') and obj.date_action_last: - base = datetime.strptime(obj.date_action_last, '%Y-%m-%d %H:%M:%S') - else: - base = datetime.strptime(obj.create_date[:19], '%Y-%m-%d %H:%M:%S') - elif action.trg_date_type=='deadline' and hasattr(obj, 'date_deadline') \ - and obj.date_deadline: - base = datetime.strptime(obj.date_deadline, '%Y-%m-%d %H:%M:%S') - elif action.trg_date_type=='date' and hasattr(obj, 'date') and obj.date: - base = datetime.strptime(obj.date, '%Y-%m-%d %H:%M:%S') - if base: - fnct = { - 'minutes': lambda interval: timedelta(minutes=interval), - 'day': lambda interval: timedelta(days=interval), - 'hour': lambda interval: timedelta(hours=interval), - 'month': lambda interval: timedelta(months=interval), - } - d = base + fnct[action.trg_date_range_type](action.trg_date_range) - dt = d.strftime('%Y-%m-%d %H:%M:%S') - ok = False - if hasattr(obj, 'date_action_last') and hasattr(obj, 'date_action_next'): - ok = (dt <= time.strftime('%Y-%m-%d %H:%M:%S')) and \ - ((not obj.date_action_next) or \ - (dt >= obj.date_action_next and \ - obj.date_action_last < obj.date_action_next)) - if not ok: - if not obj.date_action_next or dt < obj.date_action_next: - obj.date_action_next = dt - model_obj.write(cr, uid, [obj.id], {'date_action_next': dt}, context) - else: - ok = action.trg_date_type == 'none' - if ok: self.do_action(cr, uid, action, model_obj, obj, context) break From 42ca50081352be6ecc44b3cc746553dbbda5c0a0 Mon Sep 17 00:00:00 2001 From: "Daniel Watkins (credativ)" Date: Thu, 9 Sep 2010 14:26:26 +0100 Subject: [PATCH 002/225] SQL case fix. bzr revid: daniel.watkins@credativ.co.uk-20100909132626-wl8k91c4ae19ounv --- addons/base_action_rule/base_action_rule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 16a628d9529..75b3273dcab 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -144,7 +144,7 @@ the rule to mark CC(mail to any other person defined in actions)."), # Searching for action rules cr.execute("SELECT model.model, rule.id FROM base_action_rule rule \ LEFT JOIN ir_model model on (model.id = rule.model_id) \ - where active") + WHERE active") res = cr.fetchall() # Check if any rule matching with current object for obj_name, rule_id in res: From 7c33b854ceafd9bbe4f5053ae85fab5767879d34 Mon Sep 17 00:00:00 2001 From: "Daniel Watkins (credativ)" Date: Thu, 9 Sep 2010 14:26:50 +0100 Subject: [PATCH 003/225] Comment change. bzr revid: daniel.watkins@credativ.co.uk-20100909132650-k4i750ub6y77rx8w --- addons/base_action_rule/base_action_rule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 75b3273dcab..fbb28c6fcc1 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -220,7 +220,7 @@ the rule to mark CC(mail to any other person defined in actions)."), for obj_id in model_pool.search(cr, uid, [], context=context): print " OBJ: %s" % (obj_id,) obj = model_pool.browse(cr, uid, obj_id, context=context) - # Calculate when the action should next occur for this object + # Calculate when this action should next occur for this object base = False if rule.trg_date_type=='create' and hasattr(obj, 'create_date'): base = datetime.strptime(obj.create_date[:19], '%Y-%m-%d %H:%M:%S') From e5465c80c81d75c5b2f1731546fbeeb29e7b79f0 Mon Sep 17 00:00:00 2001 From: "Daniel Watkins (credativ)" Date: Thu, 9 Sep 2010 14:27:21 +0100 Subject: [PATCH 004/225] Don't run rules with time conditions from the create/write methods of models. bzr revid: daniel.watkins@credativ.co.uk-20100909132721-wlnqp4uzwf3s7gjb --- addons/base_action_rule/base_action_rule.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index fbb28c6fcc1..28cafade079 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -152,7 +152,10 @@ the rule to mark CC(mail to any other person defined in actions)."), continue else: obj = self.pool.get(obj_name) - self._action(cr, uid, [rule_id], obj.browse(cr, uid, ids, context=context), context=context) + # If the rule doesn't involve a time condition, run it immediately + # Otherwise we let the scheduler run the action + if self.browse(cr, uid, rule_id, context=context).trg_date_type == 'none': + self._action(cr, uid, [rule_id], obj.browse(cr, uid, ids, context=context), context=context) return True def _create(self, old_create, model, context=None): From 6027763a6ac656c9fd5dd6a4377e6c24ecd91e0c Mon Sep 17 00:00:00 2001 From: "Daniel Watkins (credativ)" Date: Thu, 9 Sep 2010 14:50:42 +0100 Subject: [PATCH 005/225] Remove debugging statements. bzr revid: daniel.watkins@credativ.co.uk-20100909135042-0qvo42y2l9jfq70w --- addons/base_action_rule/base_action_rule.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 28cafade079..3038b43136a 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -212,8 +212,6 @@ the rule to mark CC(mail to any other person defined in actions)."), rules = self.browse(cr, uid, rule_ids, context=context) for rule in rules: - print "RULE: %s" % (rule,) - print " %s" % (rule.last_run,) model = rule.model_id.model model_pool = self.pool.get(model) last_run = False @@ -221,7 +219,6 @@ the rule to mark CC(mail to any other person defined in actions)."), last_run = datetime.strptime(rule.last_run[:19], '%Y-%m-%d %H:%M:%S') now = datetime.now() for obj_id in model_pool.search(cr, uid, [], context=context): - print " OBJ: %s" % (obj_id,) obj = model_pool.browse(cr, uid, obj_id, context=context) # Calculate when this action should next occur for this object base = False @@ -245,9 +242,7 @@ the rule to mark CC(mail to any other person defined in actions)."), 'month': lambda interval: timedelta(months=interval), } d = base + fnct[rule.trg_date_range_type](rule.trg_date_range) - print " D: %s" % (d,) if (not last_run or (last_run <= d < now)): - print " RUNNING" self._action(cr, uid, [rule.id], [obj], context=context) rule_pool.write(cr, uid, [rule.id], {'last_run': now}, context=context) From 9b37ccf4e29c54271d767140b80bdc75a67815c9 Mon Sep 17 00:00:00 2001 From: "Daniel Watkins (credativ)" Date: Thu, 9 Sep 2010 15:13:28 +0100 Subject: [PATCH 006/225] Extract strptime calls to make code look clearer. bzr revid: daniel.watkins@credativ.co.uk-20100909141328-3qz1ome23ani3yrm --- addons/base_action_rule/base_action_rule.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 3038b43136a..73fd96f93c9 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -29,6 +29,11 @@ import re import time import tools + +def get_datetime(date_field): + return datetime.strptime(date_field[:19], '%Y-%m-%d %H:%M:%S') + + class base_action_rule(osv.osv): """ Base Action Rules """ @@ -216,24 +221,24 @@ the rule to mark CC(mail to any other person defined in actions)."), model_pool = self.pool.get(model) last_run = False if rule.last_run: - last_run = datetime.strptime(rule.last_run[:19], '%Y-%m-%d %H:%M:%S') + last_run = get_datetime(rule.last_run) now = datetime.now() for obj_id in model_pool.search(cr, uid, [], context=context): obj = model_pool.browse(cr, uid, obj_id, context=context) # Calculate when this action should next occur for this object base = False if rule.trg_date_type=='create' and hasattr(obj, 'create_date'): - base = datetime.strptime(obj.create_date[:19], '%Y-%m-%d %H:%M:%S') + base = get_datetime(obj.create_date) elif rule.trg_date_type=='action_last' and hasattr(obj, 'create_date'): if hasattr(obj, 'date_action_last') and obj.date_action_last: - base = datetime.strptime(obj.date_action_last, '%Y-%m-%d %H:%M:%S') + base = get_datetime(obj.date_action_last) else: - base = datetime.strptime(obj.create_date[:19], '%Y-%m-%d %H:%M:%S') + base = get_datetime(obj.create_date) elif rule.trg_date_type=='deadline' and hasattr(obj, 'date_deadline') \ and obj.date_deadline: - base = datetime.strptime(obj.date_deadline, '%Y-%m-%d %H:%M:%S') + base = get_datetime(obj.date_deadline) elif rule.trg_date_type=='date' and hasattr(obj, 'date') and obj.date: - base = datetime.strptime(obj.date, '%Y-%m-%d %H:%M:%S') + base = get_datetime(obj.date) if base: fnct = { 'minutes': lambda interval: timedelta(minutes=interval), From a298287a8cfdc81aac0d4d9b15724720a450150a Mon Sep 17 00:00:00 2001 From: "Daniel Watkins (credativ)" Date: Thu, 9 Sep 2010 15:25:49 +0100 Subject: [PATCH 007/225] Even better removal of get_datetime stuff. bzr revid: daniel.watkins@credativ.co.uk-20100909142549-zl1yt8s7swcibno5 --- addons/base_action_rule/base_action_rule.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 73fd96f93c9..6d62985d022 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -228,17 +228,17 @@ the rule to mark CC(mail to any other person defined in actions)."), # Calculate when this action should next occur for this object base = False if rule.trg_date_type=='create' and hasattr(obj, 'create_date'): - base = get_datetime(obj.create_date) + base = obj.create_date elif rule.trg_date_type=='action_last' and hasattr(obj, 'create_date'): if hasattr(obj, 'date_action_last') and obj.date_action_last: - base = get_datetime(obj.date_action_last) + base = obj.date_action_last else: - base = get_datetime(obj.create_date) + base = obj.create_date elif rule.trg_date_type=='deadline' and hasattr(obj, 'date_deadline') \ and obj.date_deadline: - base = get_datetime(obj.date_deadline) + base = obj.date_deadline elif rule.trg_date_type=='date' and hasattr(obj, 'date') and obj.date: - base = get_datetime(obj.date) + base = obj.date if base: fnct = { 'minutes': lambda interval: timedelta(minutes=interval), @@ -246,6 +246,7 @@ the rule to mark CC(mail to any other person defined in actions)."), 'hour': lambda interval: timedelta(hours=interval), 'month': lambda interval: timedelta(months=interval), } + base = get_datetime(base) d = base + fnct[rule.trg_date_range_type](rule.trg_date_range) if (not last_run or (last_run <= d < now)): self._action(cr, uid, [rule.id], [obj], context=context) From 350887d5ab71e706932c8eb82360582cb0616a70 Mon Sep 17 00:00:00 2001 From: "Daniel Watkins (credativ)" Date: Thu, 9 Sep 2010 15:27:08 +0100 Subject: [PATCH 008/225] Wrap long lines and remove trailing whitespace. bzr revid: daniel.watkins@credativ.co.uk-20100909142708-j16gpfvsxrh6qwno --- addons/base_action_rule/base_action_rule.py | 23 +++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 6d62985d022..0e564915c7c 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -229,28 +229,33 @@ the rule to mark CC(mail to any other person defined in actions)."), base = False if rule.trg_date_type=='create' and hasattr(obj, 'create_date'): base = obj.create_date - elif rule.trg_date_type=='action_last' and hasattr(obj, 'create_date'): + elif (rule.trg_date_type=='action_last' + and hasattr(obj, 'create_date')): if hasattr(obj, 'date_action_last') and obj.date_action_last: base = obj.date_action_last else: base = obj.create_date - elif rule.trg_date_type=='deadline' and hasattr(obj, 'date_deadline') \ - and obj.date_deadline: + elif (rule.trg_date_type=='deadline' + and hasattr(obj, 'date_deadline') + and obj.date_deadline): base = obj.date_deadline - elif rule.trg_date_type=='date' and hasattr(obj, 'date') and obj.date: + elif (rule.trg_date_type=='date' + and hasattr(obj, 'date') + and obj.date): base = obj.date if base: fnct = { - 'minutes': lambda interval: timedelta(minutes=interval), - 'day': lambda interval: timedelta(days=interval), - 'hour': lambda interval: timedelta(hours=interval), - 'month': lambda interval: timedelta(months=interval), + 'minutes': lambda interval: timedelta(minutes=interval), + 'day': lambda interval: timedelta(days=interval), + 'hour': lambda interval: timedelta(hours=interval), + 'month': lambda interval: timedelta(months=interval), } base = get_datetime(base) d = base + fnct[rule.trg_date_range_type](rule.trg_date_range) if (not last_run or (last_run <= d < now)): self._action(cr, uid, [rule.id], [obj], context=context) - rule_pool.write(cr, uid, [rule.id], {'last_run': now}, context=context) + rule_pool.write(cr, uid, [rule.id], {'last_run': now}, + context=context) def format_body(self, body): """ Foramat Action rule's body From a53aeb5c0d7d7d5ec462f2cb709c616476945d07 Mon Sep 17 00:00:00 2001 From: "Daniel Watkins (credativ)" Date: Thu, 9 Sep 2010 15:28:09 +0100 Subject: [PATCH 009/225] Make action date calculation clearer. bzr revid: daniel.watkins@credativ.co.uk-20100909142809-nrbt7f6sx3e86bxp --- addons/base_action_rule/base_action_rule.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 0e564915c7c..630cfca7e49 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -251,8 +251,9 @@ the rule to mark CC(mail to any other person defined in actions)."), 'month': lambda interval: timedelta(months=interval), } base = get_datetime(base) - d = base + fnct[rule.trg_date_range_type](rule.trg_date_range) - if (not last_run or (last_run <= d < now)): + delay = fnct[rule.trg_date_range_type](rule.trg_date_range) + action_date = base + delay + if (not last_run or (last_run <= action_date < now)): self._action(cr, uid, [rule.id], [obj], context=context) rule_pool.write(cr, uid, [rule.id], {'last_run': now}, context=context) From 5fc14722bb900337a6e7dfdcf0863246df50054a Mon Sep 17 00:00:00 2001 From: "Daniel Watkins (credativ)" Date: Thu, 9 Sep 2010 15:28:41 +0100 Subject: [PATCH 010/225] Don't run timed actions if we don't have a time base. bzr revid: daniel.watkins@credativ.co.uk-20100909142841-ntwee472cqr50t0i --- addons/base_action_rule/base_action_rule.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 630cfca7e49..cc7308dbc43 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -253,8 +253,8 @@ the rule to mark CC(mail to any other person defined in actions)."), base = get_datetime(base) delay = fnct[rule.trg_date_range_type](rule.trg_date_range) action_date = base + delay - if (not last_run or (last_run <= action_date < now)): - self._action(cr, uid, [rule.id], [obj], context=context) + if (not last_run or (last_run <= action_date < now)): + self._action(cr, uid, [rule.id], [obj], context=context) rule_pool.write(cr, uid, [rule.id], {'last_run': now}, context=context) From abe9469e889c2698234ecbb4aeecc1058b9cf66b Mon Sep 17 00:00:00 2001 From: pso Date: Fri, 19 Nov 2010 15:17:58 +0530 Subject: [PATCH 011/225] [IMP] account: Improved partner and general ledger reports for account currency bzr revid: pso@tinyerp.com-20101119094758-n54crq4lq41he265 --- .../account/report/account_general_ledger.py | 8 +++-- .../account_general_ledger_landscape.rml | 2 +- .../account/report/account_partner_ledger.py | 33 +++++++++++++------ .../report/account_partner_ledger_other.rml | 7 ++-- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/addons/account/report/account_general_ledger.py b/addons/account/report/account_general_ledger.py index 6ccfb9343a2..a1e6aca6433 100644 --- a/addons/account/report/account_general_ledger.py +++ b/addons/account/report/account_general_ledger.py @@ -191,17 +191,19 @@ class general_ledger(report_sxw.rml_parse, common_report_header): sql = """ SELECT 0 AS lid, '' AS ldate, '' AS lcode, COALESCE(SUM(l.amount_currency),0.0) AS amount_currency, '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, '' AS lperiod_id, '' AS lpartner_id, '' AS move_name, '' AS mmove_id, - '' AS currency_code, - NULL AS currency_id, + c.symbol AS currency_code, + '' AS currency_id, '' AS invoice_id, '' AS invoice_type, '' AS invoice_number, '' AS partner_name FROM account_move_line l LEFT JOIN account_move m on (l.move_id=m.id) + LEFT JOIN account_account ac on (l.account_id=ac.id) LEFT JOIN res_currency c on (l.currency_id=c.id) LEFT JOIN res_partner p on (l.partner_id=p.id) LEFT JOIN account_invoice i on (m.id =i.move_id) JOIN account_journal j on (l.journal_id=j.id) - WHERE %s AND m.state IN %s AND l.account_id = %%s + WHERE %s AND m.state IN %s AND l.account_id = %%s + group by c.symbol """ %(self.init_query, tuple(move_state)) self.cr.execute(sql, (account.id,)) res_init = self.cr.dictfetchall() diff --git a/addons/account/report/account_general_ledger_landscape.rml b/addons/account/report/account_general_ledger_landscape.rml index 430bde219e1..02e720f016e 100644 --- a/addons/account/report/account_general_ledger_landscape.rml +++ b/addons/account/report/account_general_ledger_landscape.rml @@ -327,7 +327,7 @@ [[ formatLang(line['debit'], digits=get_digits(dp='Account')) ]] [[ formatLang(line['credit'], digits=get_digits(dp='Account')) ]] [[ formatLang(line['progress'], digits=get_digits(dp='Account')) ]] [[ company.currency_id.symbol ]] - [[ (line.has_key('currency_id') and line['currency_id']==None or line['amount_currency']==None) and removeParentNode('font') ]] [[ formatLang(line['amount_currency'])]] [[ line['currency_code'] or '']] + [[ (o.currency_id and formatLang(line['amount_currency'])) or removeParentNode('font') ]] [[ line['currency_code'] or '']] diff --git a/addons/account/report/account_partner_ledger.py b/addons/account/report/account_partner_ledger.py index e66c3a9d523..8db8189ac9c 100644 --- a/addons/account/report/account_partner_ledger.py +++ b/addons/account/report/account_partner_ledger.py @@ -50,6 +50,7 @@ class third_party_ledger(report_sxw.rml_parse, common_report_header): 'display_initial_balance':self._display_initial_balance, 'display_currency':self._display_currency, 'get_target_move': self._get_target_move, + 'sum_currency_amount_account': self._sum_currency_amount_account }) def set_context(self, objects, data, ids, report_type=None): @@ -178,7 +179,8 @@ class third_party_ledger(report_sxw.rml_parse, common_report_header): " " + RECONCILE_TAG + " "\ "AND " + self.init_query + " ", (partner.id, tuple(move_state), tuple(self.account_ids))) - return self.cr.fetchall() + res = self.cr.fetchall() + return res def _sum_debit_partner(self, partner): move_state = ['draft','posted'] @@ -385,16 +387,27 @@ class third_party_ledger(report_sxw.rml_parse, common_report_header): return 'Receivable and Payable Accounts' return '' - def _sum_currency_amount_account(self, account, form): - self._set_get_account_currency_code(account.id) - self.cr.execute("SELECT sum(aml.amount_currency) FROM account_move_line as aml,res_currency as rc WHERE aml.currency_id = rc.id AND aml.account_id= %s ", (account.id,)) +# def _set_get_account_currency_code(self, account_id): +# self.cr.execute("SELECT c.symbol AS code "\ +# "FROM res_currency c, account_account AS ac "\ +# "WHERE ac.id = %s AND ac.currency_id = c.id" % (account_id)) +# result = self.cr.fetchone() +# if result: +# self.account_currency = result[0] +# else: +# self.account_currency = False + + def _sum_currency_amount_account(self, account): +# self._set_get_account_currency_code(account.id) + self.cr.execute("SELECT sum(aml.amount_currency) FROM account_move_line as aml,res_currency as rc WHERE aml.currency_id = rc.id AND aml.account_id= %s" %(account.id)) total = self.cr.fetchone() - if self.account_currency: - return_field = str(total[0]) + self.account_currency - return return_field - else: - currency_total = self.tot_currency = 0.0 - return currency_total + return total[0] or 0.0 +# if self.amount_currency: +# return_field = total[0] + self.amount_currency +# return return_field +# else: +# currency_total = self.tot_currency = 0.0 +# return currency_total def _display_initial_balance(self, data): if self.initial_balance: diff --git a/addons/account/report/account_partner_ledger_other.rml b/addons/account/report/account_partner_ledger_other.rml index c3315dde64d..36aadc9e0dc 100644 --- a/addons/account/report/account_partner_ledger_other.rml +++ b/addons/account/report/account_partner_ledger_other.rml @@ -327,7 +327,8 @@ - + + @@ -656,7 +657,7 @@ [[ formatLang(get_intial_balance(p)[0][2]) ]] [[ company.currency_id.symbol ]] - + [[ p.property_account_receivable.currency_id and formatLang(sum_currency_amount_account(p.property_account_receivable), digits=get_digits(dp='Account')) + p.property_account_receivable.currency_id.symbol or '' ]] @@ -689,7 +690,7 @@ [[ formatLang((line['progress'])) ]] [[ company.currency_id.symbol ]] - [[ (line['currency_id']==None or line['amount_currency']==None) and removeParentNode('font') ]] [[ formatLang(line['amount_currency'] ) ]] [[ line['currency_code'] or '' ]] + [[ (p.property_account_receivable.currency_id and formatLang(line['amount_currency'])) or removeParentNode('font') ]] [[ line['currency_code'] or '']] From 216fe9522dbe0fa73c5778b4a81bf4da0215ab62 Mon Sep 17 00:00:00 2001 From: pso Date: Fri, 19 Nov 2010 15:31:19 +0530 Subject: [PATCH 012/225] [IMP] account: removed unnecessary var bzr revid: pso@tinyerp.com-20101119100119-1fs913166qqc1dvm --- addons/account/report/account_partner_ledger.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/account/report/account_partner_ledger.py b/addons/account/report/account_partner_ledger.py index 8db8189ac9c..415597e3201 100644 --- a/addons/account/report/account_partner_ledger.py +++ b/addons/account/report/account_partner_ledger.py @@ -179,8 +179,7 @@ class third_party_ledger(report_sxw.rml_parse, common_report_header): " " + RECONCILE_TAG + " "\ "AND " + self.init_query + " ", (partner.id, tuple(move_state), tuple(self.account_ids))) - res = self.cr.fetchall() - return res + return self.cr.fetchall() def _sum_debit_partner(self, partner): move_state = ['draft','posted'] From 4482eeec0565301ada78bef83b2ef7ab341fc7d8 Mon Sep 17 00:00:00 2001 From: pso Date: Fri, 19 Nov 2010 17:36:16 +0530 Subject: [PATCH 013/225] [IMP] account: Improved general ledger report bzr revid: pso@tinyerp.com-20101119120616-tbtwepubi2224ny8 --- addons/account/report/account_general_ledger.rml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/report/account_general_ledger.rml b/addons/account/report/account_general_ledger.rml index 2a3bfda8e48..feeaa1fa18c 100644 --- a/addons/account/report/account_general_ledger.rml +++ b/addons/account/report/account_general_ledger.rml @@ -340,7 +340,7 @@ [[formatLang(sum_debit_account(o)) ]] [[formatLang(sum_credit_account(o)) ]] [[formatLang(sum_balance_account(o)) ]] [[ company.currency_id.symbol ]] - [[ o.currency_id and sum_currency_amount_account(o) +o.currency_id.symbol or '' ]] + [[ (o.currency_id and formatLang(sum_currency_amount_account(o))) or removeParentNode('font') ]] [[ o.currency_id.symbol or '']] From 971d02737ad087fd0c62d379f03c89bb5b543cf3 Mon Sep 17 00:00:00 2001 From: pso Date: Fri, 19 Nov 2010 18:58:58 +0530 Subject: [PATCH 014/225] [IMP] account: Improved general ledger report bzr revid: pso@tinyerp.com-20101119132858-58rfm2hxtd1xha52 --- addons/account/report/account_general_ledger_landscape.rml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/report/account_general_ledger_landscape.rml b/addons/account/report/account_general_ledger_landscape.rml index 02e720f016e..e91bedb4a5d 100644 --- a/addons/account/report/account_general_ledger_landscape.rml +++ b/addons/account/report/account_general_ledger_landscape.rml @@ -301,7 +301,7 @@ [[ formatLang(sum_debit_account(o), digits=get_digits(dp='Account')) ]] [[ formatLang(sum_credit_account(o), digits=get_digits(dp='Account')) ]] [[ formatLang(sum_balance_account(o), digits=get_digits(dp='Account')) ]] [[ company.currency_id.symbol ]] - [[ o.currency_id and formatLang(sum_currency_amount_account(o), digits=get_digits(dp='Account')) + o.currency_id.code or '' ]] + [[ o.currency_id and formatLang(sum_currency_amount_account(o), digits=get_digits(dp='Account')) + o.currency_id.symbol or '' ]] From 6b0d611eb15d8afda66c92648e95fac60d359c19 Mon Sep 17 00:00:00 2001 From: pso Date: Tue, 23 Nov 2010 12:49:48 +0530 Subject: [PATCH 015/225] [IMP] account: Improved general and partner ledger reports for currency bzr revid: pso@tinyerp.com-20101123071948-v6c42bqfn0wvcj7x --- .../account/report/account_general_ledger.py | 29 ++++++++++++++----- .../account/report/account_general_ledger.rml | 4 +-- .../account_general_ledger_landscape.rml | 3 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/addons/account/report/account_general_ledger.py b/addons/account/report/account_general_ledger.py index a1e6aca6433..4052fa650f9 100644 --- a/addons/account/report/account_general_ledger.py +++ b/addons/account/report/account_general_ledger.py @@ -170,13 +170,20 @@ class general_ledger(report_sxw.rml_parse, common_report_header): else: sql_sort='l.date' sql = """ - SELECT l.id AS lid, l.date AS ldate, j.code AS lcode, l.currency_id,l.amount_currency,l.ref AS lref, l.name AS lname, COALESCE(l.debit,0) AS debit, COALESCE(l.credit,0) AS credit, l.period_id AS lperiod_id, l.partner_id AS lpartner_id, + SELECT l.id AS lid, l.date AS ldate, j.code AS lcode, l.currency_id, + case when a.currency_id is not null then + l.amount_currency + else + 0.0 + end as amount_currency, + l.ref AS lref, l.name AS lname, COALESCE(l.debit,0) AS debit, COALESCE(l.credit,0) AS credit, l.period_id AS lperiod_id, l.partner_id AS lpartner_id, m.name AS move_name, m.id AS mmove_id, c.symbol AS currency_code, i.id AS invoice_id, i.type AS invoice_type, i.number AS invoice_number, p.name AS partner_name FROM account_move_line l JOIN account_move m on (l.move_id=m.id) + LEFT JOIN account_account a ON (l.account_id=a.id) LEFT JOIN res_currency c on (l.currency_id=c.id) LEFT JOIN res_partner p on (l.partner_id=p.id) LEFT JOIN account_invoice i on (m.id =i.move_id) @@ -189,25 +196,31 @@ class general_ledger(report_sxw.rml_parse, common_report_header): if res_lines and self.init_balance: #FIXME: replace the label of lname with a string translatable sql = """ - SELECT 0 AS lid, '' AS ldate, '' AS lcode, COALESCE(SUM(l.amount_currency),0.0) AS amount_currency, '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, '' AS lperiod_id, '' AS lpartner_id, - '' AS move_name, '' AS mmove_id, + SELECT 0 AS lid, '' AS ldate, '' AS lcode, + sum(case when a.currency_id is not null then + l.amount_currency + else + 0.0 + end) as amount_currency, + '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, '' AS lperiod_id, '' AS lpartner_id, + '' AS move_name, '' AS mmove_id, c.symbol AS currency_code, - '' AS currency_id, + l.currency_id AS currency_id, '' AS invoice_id, '' AS invoice_type, '' AS invoice_number, '' AS partner_name FROM account_move_line l LEFT JOIN account_move m on (l.move_id=m.id) - LEFT JOIN account_account ac on (l.account_id=ac.id) + LEFT JOIN account_account a ON (l.account_id=a.id) LEFT JOIN res_currency c on (l.currency_id=c.id) LEFT JOIN res_partner p on (l.partner_id=p.id) LEFT JOIN account_invoice i on (m.id =i.move_id) JOIN account_journal j on (l.journal_id=j.id) WHERE %s AND m.state IN %s AND l.account_id = %%s - group by c.symbol + group by c.symbol , l.currency_id """ %(self.init_query, tuple(move_state)) self.cr.execute(sql, (account.id,)) res_init = self.cr.dictfetchall() - res = res_init + res_lines + res = res_init + res_lines account_sum = 0.0 inv_types = { 'out_invoice': 'CI', 'in_invoice': 'SI', 'out_refund': 'OR', 'in_refund': 'SR', } for l in res: @@ -224,6 +237,8 @@ class general_ledger(report_sxw.rml_parse, common_report_header): l['amount_currency'] = abs(l['amount_currency']) * -1 if l['amount_currency'] != None: self.tot_currency = self.tot_currency + l['amount_currency'] + self.cr.execute("select distinct currency_id from account_invoice") + l['cur_id']=self.cr.fetchall() return res def _sum_debit_account(self, account): diff --git a/addons/account/report/account_general_ledger.rml b/addons/account/report/account_general_ledger.rml index feeaa1fa18c..d91b9bbca5c 100644 --- a/addons/account/report/account_general_ledger.rml +++ b/addons/account/report/account_general_ledger.rml @@ -340,7 +340,7 @@ [[formatLang(sum_debit_account(o)) ]] [[formatLang(sum_credit_account(o)) ]] [[formatLang(sum_balance_account(o)) ]] [[ company.currency_id.symbol ]] - [[ (o.currency_id and formatLang(sum_currency_amount_account(o))) or removeParentNode('font') ]] [[ o.currency_id.symbol or '']] + [[ o.currency_id and sum_currency_amount_account(o) +o.currency_id.symbol or '' ]] @@ -362,7 +362,7 @@ [[ formatLang(line['debit']) ]] [[ formatLang(line['credit']) ]] [[ formatLang(line['progress']) ]] [[ company.currency_id.symbol ]] - [[ (line.has_key('currency_id') and line['currency_id']==None or line['amount_currency']==None) and removeParentNode('font') ]] [[ formatLang(line['amount_currency'])]] [[ line['currency_code'] or '']] + [[ (len(line['cur_id'])==1 and o.currency_id.id==line['currency_id'] and formatLang(line['amount_currency'])) or removeParentNode('font') ]] [[ line['currency_code'] or '']] diff --git a/addons/account/report/account_general_ledger_landscape.rml b/addons/account/report/account_general_ledger_landscape.rml index e91bedb4a5d..6c6da958deb 100644 --- a/addons/account/report/account_general_ledger_landscape.rml +++ b/addons/account/report/account_general_ledger_landscape.rml @@ -327,7 +327,8 @@ [[ formatLang(line['debit'], digits=get_digits(dp='Account')) ]] [[ formatLang(line['credit'], digits=get_digits(dp='Account')) ]] [[ formatLang(line['progress'], digits=get_digits(dp='Account')) ]] [[ company.currency_id.symbol ]] - [[ (o.currency_id and formatLang(line['amount_currency'])) or removeParentNode('font') ]] [[ line['currency_code'] or '']] + + [[ (len(line['cur_id'])==1 and o.currency_id.id==line['currency_id'] and formatLang(line['amount_currency'])) or removeParentNode('font') ]] [[ line['currency_code'] or '']] From f4ebea2992d16e862ac75a0e5709a6ebac4163bf Mon Sep 17 00:00:00 2001 From: "ksa (Open ERP)" Date: Tue, 23 Nov 2010 18:54:34 +0530 Subject: [PATCH 016/225] [IMP]: Apply removing changes when merge branch bzr revid: ksa@tinyerp.co.in-20101123132434-fm0u05iasfpt0c3p --- addons/mrp/mrp.py | 22 ++++++++++++++++++++-- addons/mrp/mrp_view.xml | 15 ++++++++------- addons/mrp/wizard/mrp_price.py | 2 +- addons/product/product.py | 3 ++- addons/stock/stock.py | 16 ++++++++++++++-- addons/stock/wizard/stock_splitinto.py | 4 ++-- 6 files changed, 47 insertions(+), 15 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 4f5b8f24e14..b42d3797b2f 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -53,11 +53,23 @@ class mrp_workcenter(osv.osv): 'costs_journal_id': fields.many2one('account.analytic.journal', 'Analytic Journal'), 'costs_general_account_id': fields.many2one('account.account', 'General Account', domain=[('type','<>','view')]), 'resource_id': fields.many2one('resource.resource','Resource', ondelete='cascade', required=True), + 'product_id': fields.many2one('product.product','Product'), } _defaults = { 'capacity_per_cycle': 1.0, 'resource_type': 'material', } + + def on_change_product_cost(self, cr, uid, ids, product_id, context=None): + if context is None: + context = {} + res = {'value':{}} + + if product_id: + cost = self.pool.get('product.product').browse(cr, uid, product_id, context=context) + res = {'value' : {'costs_hour' :cost.standard_price }} + return res + mrp_workcenter() @@ -737,7 +749,10 @@ class mrp_production(osv.osv): 'account_id': account, 'general_account_id': wc.costs_general_account_id.id, 'journal_id': wc.costs_journal_id.id, - 'code': wc.code + 'ref': wc.code, + 'product_id': wc.product_id.id, + 'unit_amount': wc.costs_hour * wc.time_cycle, + 'product_uom_id': wc.product_id.uom_id.id } ) if wc.costs_journal_id and wc.costs_general_account_id: value = wc_line.cycle * wc.costs_cycle @@ -750,7 +765,10 @@ class mrp_production(osv.osv): 'account_id': account, 'general_account_id': wc.costs_general_account_id.id, 'journal_id': wc.costs_journal_id.id, - 'code': wc.code, + 'ref': wc.code, + 'product_id': wc.product_id.id, + 'unit_amount': wc.costs_hour * wc.time_cycle, + 'product_uom_id': wc.product_id.uom_id.id } ) return amount diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index 4f6f0c88d54..ea85940d451 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -160,12 +160,13 @@ + - - + + @@ -649,9 +650,9 @@ -