Merge lp:~openbig/bigconsulting/scheduler into lp:bigconsulting

Proposed by gpa(OpenERP)
Status: Merged
Merged at revision: 89
Proposed branch: lp:~openbig/bigconsulting/scheduler
Merge into: lp:bigconsulting
Diff against target: 343 lines (+251/-3)
6 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+202/-0)
account_invoice_cash_discount/wizard/wizard_discount_reconcile.py (+8/-2)
account_payment_discount_extension/__terp__.py (+1/-0)
account_payment_discount_extension/account_payment_discount.py (+22/-1)
account_payment_discount_extension/account_payment_discount_data.xml (+17/-0)
account_payment_discount_extension/wizard/wizard_payment_discount_order.py (+1/-0)
To merge this branch: bzr merge lp:~openbig/bigconsulting/scheduler
Reviewer Review Type Date Requested Status
openbig Pending
Review via email: mp+35365@code.launchpad.net

Description of the change

added scheduler

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_invoice_cash_discount/account_invoice_cash_discount.py'
--- account_invoice_cash_discount/account_invoice_cash_discount.py 2010-08-13 10:34:49 +0000
+++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-09-14 05:41:08 +0000
@@ -24,6 +24,8 @@
24from tools import config24from tools import config
25import time25import time
26from tools.translate import _26from tools.translate import _
27import netsvc
28
2729
28class account_payment_term(osv.osv):30class account_payment_term(osv.osv):
29 _name = "account.payment.term"31 _name = "account.payment.term"
@@ -871,5 +873,205 @@
871 }873 }
872account_bank_statement_line()874account_bank_statement_line()
873875
876
877class account_move_line(osv.osv):
878 _inherit="account.move.line"
879
880 def reconcile(self, cr, uid, ids, type='auto', writeoff_acc_id=False, writeoff_period_id=False, writeoff_journal_id=False, context={}):
881
882 id_set = ','.join(map(str, ids))
883 res_users_obj = self.pool.get('res.users')
884 lines = self.browse(cr, uid, ids, context=context)
885 unrec_lines = filter(lambda x: not x['reconcile_id'], lines)
886 credit = debit = 0.0
887 currency = 0.0
888 account_id = False
889 partner_id = False
890 invoice = False
891 writeoff_lines = []
892 for line in unrec_lines:
893 if line.invoice:
894 invoice = line.invoice
895 if line.state <> 'valid':
896 raise osv.except_osv(_('Error'),
897 _('Entry "%s" is not valid !') % line.name)
898 credit += line['credit']
899 debit += line['debit']
900 currency += line['amount_currency'] or 0.0
901 account_id = line['account_id']['id']
902 account_type = line['account_id']['type']
903 partner_id = (line['partner_id'] and line['partner_id']['id']) or False
904 writeoff = debit - credit
905 # Ifdate_p in context => take this date
906 if context.has_key('date_p') and context['date_p']:
907 date=context['date_p']
908 else:
909 date = time.strftime('%Y-%m-%d')
910
911 cr.execute('SELECT account_id, reconcile_id '\
912 'FROM account_move_line '\
913 'WHERE id IN %s '\
914 'GROUP BY account_id,reconcile_id',
915 (tuple(ids),))
916 r = cr.fetchall()
917#TODO: move this check to a constraint in the account_move_reconcile object
918 if (len(r) != 1) and not context.get('fy_closing', False):
919 raise osv.except_osv(_('Error'), _('Entries are not of the same account or already reconciled ! '))
920 if not unrec_lines:
921 raise osv.except_osv(_('Error'), _('Entry is already reconciled'))
922 account = self.pool.get('account.account').browse(cr, uid, account_id, context=context)
923 if not context.get('fy_closing', False) and not account.reconcile:
924 raise osv.except_osv(_('Error'), _('The account is not defined to be reconciled !'))
925 if r[0][1] != None:
926 raise osv.except_osv(_('Error'), _('Some entries are already reconciled !'))
927
928 if (not self.pool.get('res.currency').is_zero(cr, uid, account.company_id.currency_id, writeoff)) or \
929 (account.currency_id and (not self.pool.get('res.currency').is_zero(cr, uid, account.currency_id, currency))):
930 if not writeoff_acc_id:
931 raise osv.except_osv(_('Warning'), _('You have to provide an account for the write off entry !'))
932 if writeoff > 0:
933 debit = writeoff
934 credit = 0.0
935 self_credit = writeoff
936 self_debit = 0.0
937 else:
938 debit = 0.0
939 credit = -writeoff
940 self_credit = 0.0
941 self_debit = -writeoff
942
943 # If comment exist in context, take it
944 if 'comment' in context and context['comment']:
945 libelle=context['comment']
946 else:
947 libelle='Write-Off'
948
949 cur_obj = self.pool.get('res.currency')
950 cur_id = False
951 amount_cur = 0.00
952
953 writeoff_lines.append(
954 (0, 0, {
955 'name':libelle,
956 'debit':self_debit,
957 'credit':self_credit,
958 'account_id':account_id,
959 'date':date,
960 'partner_id':partner_id,
961 'currency_id': cur_id or (account.currency_id.id or False),
962 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0)
963 })),
964
965 writeoff_lines.append((0, 0, {
966 'name':libelle,
967 'debit':debit,
968 'credit':credit,
969 'account_id':writeoff_acc_id,
970 'analytic_account_id': context.get('analytic_id', False),
971 'date':date,
972 'partner_id':partner_id,
973 'currency_id': cur_id or (account.currency_id.id or False),
974 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0)
975 }))
976
977 #####################################################
978 if invoice.type == 'out_invoice':
979 partner_acc_id = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context).property_account_receivable.id
980 elif invoice.type=='in_invoice':
981 partner_acc_id = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context).property_account_payable.id
982
983 if context.get('company_currency_id',False) != context.get('currency_id',False):
984 expense_acc = res_users_obj.browse(cr, uid, uid, context=context).company_id.expense_account_id
985 revene_acc = res_users_obj.browse(cr, uid, uid, context=context).company_id.revenue_account_id
986
987 amount_cur = cur_obj.compute(cr, uid, context.get('company_currency_id',False), context.get('currency_id',False), abs(writeoff), context=context)
988 cur_id = context.get('currency_id',False)
989 currency_diff = amount_cur - abs(writeoff)
990
991 if currency_diff > 0.0:
992 writeoff_lines.append((0, 0, {
993 'name':libelle,
994 'debit':0.0,
995 'credit':abs(currency_diff),
996 'account_id':revene_acc.id,
997 'date':date,
998 'partner_id':partner_id,
999 'currency_id': cur_id or (account.currency_id.id or False),
1000 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0)
1001 })),
1002
1003 writeoff_lines.append((0, 0, {
1004 'name':libelle,
1005 'debit':abs(currency_diff),
1006 'credit':0.0,
1007 'account_id':2,
1008 'analytic_account_id': context.get('analytic_id', False),
1009 'date':date,
1010 'partner_id':partner_id,
1011 'currency_id': cur_id or (account.currency_id.id or False),
1012 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0)
1013 }))
1014 else:
1015 writeoff_lines.append((0, 0, {
1016 'name':libelle,
1017 'debit':abs(currency_diff),
1018 'credit':0.0,
1019 'account_id':3,
1020 'date':date,
1021 'partner_id':partner_id,
1022 'currency_id': cur_id or (account.currency_id.id or False),
1023 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0)
1024 })),
1025
1026 writeoff_lines.append((0, 0, {
1027 'name':libelle,
1028 'debit':0.0,
1029 'credit':abs(currency_diff),
1030 'account_id':expense_acc.id,
1031 'analytic_account_id': context.get('analytic_id', False),
1032 'date':date,
1033 'partner_id':partner_id,
1034 'currency_id': cur_id or (account.currency_id.id or False),
1035 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0)
1036 }))
1037 ##########################################3
1038
1039 writeoff_move_id = self.pool.get('account.move').create(cr, uid, {
1040 'period_id': writeoff_period_id,
1041 'journal_id': writeoff_journal_id,
1042 'date':date,
1043 'state': 'draft',
1044 'line_id': writeoff_lines
1045 })
1046 writeoff_line_ids = self.search(cr, uid, [('move_id', '=', writeoff_move_id), ('account_id', '=', account_id)])
1047 if account_id == writeoff_acc_id:
1048 writeoff_line_ids = [writeoff_line_ids[1]]
1049
1050 if invoice:
1051 if (invoice.type == 'out_invoice') or (invoice.type == 'in_invoice'):
1052 condition_1 = (account_type == 'payable' and writeoff > 0.0)
1053 condition_2 = (account_type == 'receivable' and writeoff < 0.0)
1054 else:
1055 condition_1 = (account_type == 'payable' and writeoff < 0.0)
1056 condition_2 = (account_type == 'receivable' and writeoff > 0.0)
1057 if condition_1 or condition_2:
1058 writeoff_line_ids = self.search(cr, uid, [('move_id', '=', writeoff_move_id), ('account_id', 'in', (account_id,writeoff_acc_id))])
1059 self.pool.get('account.move.line').write(cr ,uid, writeoff_line_ids, {'name':_('Currency Profit/Loss')})
1060 ids += writeoff_line_ids
1061
1062 r_id = self.pool.get('account.move.reconcile').create(cr, uid, {
1063 #'name': date,
1064 'type': type,
1065 'line_id': map(lambda x: (4,x,False), ids),
1066 'line_partial_ids': map(lambda x: (3,x,False), ids)
1067 })
1068 wf_service = netsvc.LocalService("workflow")
1069 # the id of the move.reconcile is written in the move.line (self) by the create method above
1070 # because of the way the line_id are defined: (4, x, False)
1071 for id in ids:
1072 wf_service.trg_trigger(uid, 'account.move.line', id, cr)
1073 return r_id
1074
1075account_move_line()
874# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:1076# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
8751077
8761078
=== modified file 'account_invoice_cash_discount/wizard/wizard_discount_reconcile.py'
--- account_invoice_cash_discount/wizard/wizard_discount_reconcile.py 2010-09-13 09:11:53 +0000
+++ account_invoice_cash_discount/wizard/wizard_discount_reconcile.py 2010-09-14 05:41:08 +0000
@@ -69,9 +69,13 @@
69def _trans_rec_reconcile(self, cr, uid, data, context=None):69def _trans_rec_reconcile(self, cr, uid, data, context=None):
70 pool = pooler.get_pool(cr.dbname)70 pool = pooler.get_pool(cr.dbname)
71 account_move_line_obj = pool.get('account.move.line')71 account_move_line_obj = pool.get('account.move.line')
7272 res_users_obj = pool.get('res.users')
73 invoice_obj = pool.get('account.inovice')
74
73 form = data['form']75 form = data['form']
74 account_id = form.get('writeoff_acc_id', False) or form.get('discount_acc_id', False)76 account_id = form.get('writeoff_acc_id', False) or form.get('discount_acc_id', False)
77 company_currecy_id = res_users_obj.browse(cr, uid, uid, context=context).company_id.currency_id.id
78 invoice_currecy_id = account_move_line_obj.browse(cr, uid, data['id'], context=context).invoice.currency_id.id
75 context['date_p'] = form.get('date_p', False)79 context['date_p'] = form.get('date_p', False)
76 date = False80 date = False
77 if context['date_p']:81 if context['date_p']:
@@ -80,7 +84,9 @@
80 period_id = False84 period_id = False
81 if len(ids):85 if len(ids):
82 period_id = ids[0]86 period_id = ids[0]
8387
88 context['company_currency_id'] = company_currecy_id
89 context['currency_id'] = invoice_currecy_id
84 journal_id = form.get('journal_id', False)90 journal_id = form.get('journal_id', False)
85 context['comment'] = form.get('comment', False)91 context['comment'] = form.get('comment', False)
86 context['analytic_id'] = form.get('analytic_id', False)92 context['analytic_id'] = form.get('analytic_id', False)
8793
=== modified file 'account_payment_discount_extension/__terp__.py'
--- account_payment_discount_extension/__terp__.py 2010-08-20 12:17:29 +0000
+++ account_payment_discount_extension/__terp__.py 2010-09-14 05:41:08 +0000
@@ -35,6 +35,7 @@
35 "update_xml" : [35 "update_xml" : [
36 "account_payment_disocunt_wizard.xml",36 "account_payment_disocunt_wizard.xml",
37 "account_payment_discount_view.xml",37 "account_payment_discount_view.xml",
38 "account_payment_discount_data.xml",
38 ],39 ],
39 "active": False,40 "active": False,
40 "installable": True,41 "installable": True,
4142
=== modified file 'account_payment_discount_extension/account_payment_discount.py'
--- account_payment_discount_extension/account_payment_discount.py 2010-09-20 14:25:34 +0000
+++ account_payment_discount_extension/account_payment_discount.py 2010-09-14 05:41:08 +0000
@@ -25,7 +25,7 @@
25import time25import time
26from datetime import datetime26from datetime import datetime
27from dateutil.relativedelta import relativedelta27from dateutil.relativedelta import relativedelta
2828from mx import DateTime
2929
30class payment_order(osv.osv):30class payment_order(osv.osv):
31 _inherit='payment.order'31 _inherit='payment.order'
@@ -39,6 +39,7 @@
39 _columns={39 _columns={
40 'next_payment_date': fields.date('Next Payment Date', states={'open':[('readonly',True)],'close':[('readonly',True)]},),40 'next_payment_date': fields.date('Next Payment Date', states={'open':[('readonly',True)],'close':[('readonly',True)]},),
41 }41 }
42
42 def action_date_assign(self, cr, uid, ids, *args):43 def action_date_assign(self, cr, uid, ids, *args):
43 data = super(account_invoice,self).action_date_assign(cr, uid, ids, *args)44 data = super(account_invoice,self).action_date_assign(cr, uid, ids, *args)
44 for inv in self.browse(cr, uid, ids):45 for inv in self.browse(cr, uid, ids):
@@ -48,7 +49,27 @@
48 delay = payment_data[0].delay49 delay = payment_data[0].delay
49 self.write(cr, uid, [inv.id], {'next_payment_date':(datetime.now() + relativedelta(days=delay)).strftime('%Y-%m-%d')})50 self.write(cr, uid, [inv.id], {'next_payment_date':(datetime.now() + relativedelta(days=delay)).strftime('%Y-%m-%d')})
50 return data51 return data
52
53 def _next_date(self, cr, uid, ids, context=None):
54 payment_term_obj = self.pool.get('account.payment.term')
55 current_date = datetime.now().strftime('%Y-%m-%d')
56 ids = self.search(cr, uid, [('state','=','open')])
57 for id in ids:
58 invoice_data = self.browse(cr, uid, id, context=context)
59 next_pay_date = invoice_data.next_payment_date
60 payment_data = payment_term_obj.browse(cr, uid, invoice_data.payment_term.id)
61 if next_pay_date:
62 if next_pay_date < current_date:
63 for dis_line in payment_data.cash_discount_ids:
64 discount_date = (DateTime.strptime(invoice_data.date_invoice, '%Y-%m-%d') + DateTime.RelativeDateTime(days=dis_line.delay)).strftime('%Y-%m-%d')
65 if discount_date > current_date:
66 self.write(cr, uid, [id], {'next_payment_date':discount_date})
67 break
68 return True
51 69
70 def check_next_date(self, cr, uid, ids=[], context=None):
71 self._next_date(cr, uid, ids, context=context)
72
52 def copy(self, cr, uid, id, default=None, context=None):73 def copy(self, cr, uid, id, default=None, context=None):
53 if default is None:74 if default is None:
54 default = {}75 default = {}
5576
=== added file 'account_payment_discount_extension/account_payment_discount_data.xml'
--- account_payment_discount_extension/account_payment_discount_data.xml 1970-01-01 00:00:00 +0000
+++ account_payment_discount_extension/account_payment_discount_data.xml 2010-09-14 05:41:08 +0000
@@ -0,0 +1,17 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data noupdate="1">
4
5 <record forcecreate="True" id="ir_cron_discount_action" model="ir.cron">
6 <field name="name">Next Payment Date</field>
7 <field name="interval_number">1</field>
8 <field name="interval_type">days</field>
9 <field name="numbercall">-1</field>
10 <field eval="False" name="doall"/>
11 <field eval="'account.invoice'" name="model"/>
12 <field eval="'check_next_date'" name="function"/>
13 <field eval="'(False,)'" name="args"/>
14 </record>
15
16 </data>
17</openerp>
018
=== modified file 'account_payment_discount_extension/wizard/wizard_payment_discount_order.py'
--- account_payment_discount_extension/wizard/wizard_payment_discount_order.py 2010-09-20 14:25:59 +0000
+++ account_payment_discount_extension/wizard/wizard_payment_discount_order.py 2010-09-14 05:41:08 +0000
@@ -27,6 +27,7 @@
27from datetime import datetime27from datetime import datetime
28from dateutil.relativedelta import relativedelta28from dateutil.relativedelta import relativedelta
29from mx import DateTime29from mx import DateTime
30
30FORM = UpdateableStr()31FORM = UpdateableStr()
3132
32FIELDS = {33FIELDS = {

Subscribers

People subscribed via source and target branches