Merge lp:~openbig/bigconsulting/scheduler into lp:bigconsulting
- scheduler
- Merge into addons
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
openbig | Pending | ||
Review via email: mp+35365@code.launchpad.net |
Commit message
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
1 | === modified file 'account_invoice_cash_discount/account_invoice_cash_discount.py' |
2 | --- account_invoice_cash_discount/account_invoice_cash_discount.py 2010-08-13 10:34:49 +0000 |
3 | +++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-09-14 05:41:08 +0000 |
4 | @@ -24,6 +24,8 @@ |
5 | from tools import config |
6 | import time |
7 | from tools.translate import _ |
8 | +import netsvc |
9 | + |
10 | |
11 | class account_payment_term(osv.osv): |
12 | _name = "account.payment.term" |
13 | @@ -871,5 +873,205 @@ |
14 | } |
15 | account_bank_statement_line() |
16 | |
17 | + |
18 | +class account_move_line(osv.osv): |
19 | + _inherit="account.move.line" |
20 | + |
21 | + def reconcile(self, cr, uid, ids, type='auto', writeoff_acc_id=False, writeoff_period_id=False, writeoff_journal_id=False, context={}): |
22 | + |
23 | + id_set = ','.join(map(str, ids)) |
24 | + res_users_obj = self.pool.get('res.users') |
25 | + lines = self.browse(cr, uid, ids, context=context) |
26 | + unrec_lines = filter(lambda x: not x['reconcile_id'], lines) |
27 | + credit = debit = 0.0 |
28 | + currency = 0.0 |
29 | + account_id = False |
30 | + partner_id = False |
31 | + invoice = False |
32 | + writeoff_lines = [] |
33 | + for line in unrec_lines: |
34 | + if line.invoice: |
35 | + invoice = line.invoice |
36 | + if line.state <> 'valid': |
37 | + raise osv.except_osv(_('Error'), |
38 | + _('Entry "%s" is not valid !') % line.name) |
39 | + credit += line['credit'] |
40 | + debit += line['debit'] |
41 | + currency += line['amount_currency'] or 0.0 |
42 | + account_id = line['account_id']['id'] |
43 | + account_type = line['account_id']['type'] |
44 | + partner_id = (line['partner_id'] and line['partner_id']['id']) or False |
45 | + writeoff = debit - credit |
46 | + # Ifdate_p in context => take this date |
47 | + if context.has_key('date_p') and context['date_p']: |
48 | + date=context['date_p'] |
49 | + else: |
50 | + date = time.strftime('%Y-%m-%d') |
51 | + |
52 | + cr.execute('SELECT account_id, reconcile_id '\ |
53 | + 'FROM account_move_line '\ |
54 | + 'WHERE id IN %s '\ |
55 | + 'GROUP BY account_id,reconcile_id', |
56 | + (tuple(ids),)) |
57 | + r = cr.fetchall() |
58 | +#TODO: move this check to a constraint in the account_move_reconcile object |
59 | + if (len(r) != 1) and not context.get('fy_closing', False): |
60 | + raise osv.except_osv(_('Error'), _('Entries are not of the same account or already reconciled ! ')) |
61 | + if not unrec_lines: |
62 | + raise osv.except_osv(_('Error'), _('Entry is already reconciled')) |
63 | + account = self.pool.get('account.account').browse(cr, uid, account_id, context=context) |
64 | + if not context.get('fy_closing', False) and not account.reconcile: |
65 | + raise osv.except_osv(_('Error'), _('The account is not defined to be reconciled !')) |
66 | + if r[0][1] != None: |
67 | + raise osv.except_osv(_('Error'), _('Some entries are already reconciled !')) |
68 | + |
69 | + if (not self.pool.get('res.currency').is_zero(cr, uid, account.company_id.currency_id, writeoff)) or \ |
70 | + (account.currency_id and (not self.pool.get('res.currency').is_zero(cr, uid, account.currency_id, currency))): |
71 | + if not writeoff_acc_id: |
72 | + raise osv.except_osv(_('Warning'), _('You have to provide an account for the write off entry !')) |
73 | + if writeoff > 0: |
74 | + debit = writeoff |
75 | + credit = 0.0 |
76 | + self_credit = writeoff |
77 | + self_debit = 0.0 |
78 | + else: |
79 | + debit = 0.0 |
80 | + credit = -writeoff |
81 | + self_credit = 0.0 |
82 | + self_debit = -writeoff |
83 | + |
84 | + # If comment exist in context, take it |
85 | + if 'comment' in context and context['comment']: |
86 | + libelle=context['comment'] |
87 | + else: |
88 | + libelle='Write-Off' |
89 | + |
90 | + cur_obj = self.pool.get('res.currency') |
91 | + cur_id = False |
92 | + amount_cur = 0.00 |
93 | + |
94 | + writeoff_lines.append( |
95 | + (0, 0, { |
96 | + 'name':libelle, |
97 | + 'debit':self_debit, |
98 | + 'credit':self_credit, |
99 | + 'account_id':account_id, |
100 | + 'date':date, |
101 | + 'partner_id':partner_id, |
102 | + 'currency_id': cur_id or (account.currency_id.id or False), |
103 | + 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0) |
104 | + })), |
105 | + |
106 | + writeoff_lines.append((0, 0, { |
107 | + 'name':libelle, |
108 | + 'debit':debit, |
109 | + 'credit':credit, |
110 | + 'account_id':writeoff_acc_id, |
111 | + 'analytic_account_id': context.get('analytic_id', False), |
112 | + 'date':date, |
113 | + 'partner_id':partner_id, |
114 | + 'currency_id': cur_id or (account.currency_id.id or False), |
115 | + 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0) |
116 | + })) |
117 | + |
118 | + ##################################################### |
119 | + if invoice.type == 'out_invoice': |
120 | + partner_acc_id = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context).property_account_receivable.id |
121 | + elif invoice.type=='in_invoice': |
122 | + partner_acc_id = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context).property_account_payable.id |
123 | + |
124 | + if context.get('company_currency_id',False) != context.get('currency_id',False): |
125 | + expense_acc = res_users_obj.browse(cr, uid, uid, context=context).company_id.expense_account_id |
126 | + revene_acc = res_users_obj.browse(cr, uid, uid, context=context).company_id.revenue_account_id |
127 | + |
128 | + amount_cur = cur_obj.compute(cr, uid, context.get('company_currency_id',False), context.get('currency_id',False), abs(writeoff), context=context) |
129 | + cur_id = context.get('currency_id',False) |
130 | + currency_diff = amount_cur - abs(writeoff) |
131 | + |
132 | + if currency_diff > 0.0: |
133 | + writeoff_lines.append((0, 0, { |
134 | + 'name':libelle, |
135 | + 'debit':0.0, |
136 | + 'credit':abs(currency_diff), |
137 | + 'account_id':revene_acc.id, |
138 | + 'date':date, |
139 | + 'partner_id':partner_id, |
140 | + 'currency_id': cur_id or (account.currency_id.id or False), |
141 | + 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0) |
142 | + })), |
143 | + |
144 | + writeoff_lines.append((0, 0, { |
145 | + 'name':libelle, |
146 | + 'debit':abs(currency_diff), |
147 | + 'credit':0.0, |
148 | + 'account_id':2, |
149 | + 'analytic_account_id': context.get('analytic_id', False), |
150 | + 'date':date, |
151 | + 'partner_id':partner_id, |
152 | + 'currency_id': cur_id or (account.currency_id.id or False), |
153 | + 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0) |
154 | + })) |
155 | + else: |
156 | + writeoff_lines.append((0, 0, { |
157 | + 'name':libelle, |
158 | + 'debit':abs(currency_diff), |
159 | + 'credit':0.0, |
160 | + 'account_id':3, |
161 | + 'date':date, |
162 | + 'partner_id':partner_id, |
163 | + 'currency_id': cur_id or (account.currency_id.id or False), |
164 | + 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0) |
165 | + })), |
166 | + |
167 | + writeoff_lines.append((0, 0, { |
168 | + 'name':libelle, |
169 | + 'debit':0.0, |
170 | + 'credit':abs(currency_diff), |
171 | + 'account_id':expense_acc.id, |
172 | + 'analytic_account_id': context.get('analytic_id', False), |
173 | + 'date':date, |
174 | + 'partner_id':partner_id, |
175 | + 'currency_id': cur_id or (account.currency_id.id or False), |
176 | + 'amount_currency': amount_cur or (account.currency_id.id and -currency or 0.0) |
177 | + })) |
178 | + ##########################################3 |
179 | + |
180 | + writeoff_move_id = self.pool.get('account.move').create(cr, uid, { |
181 | + 'period_id': writeoff_period_id, |
182 | + 'journal_id': writeoff_journal_id, |
183 | + 'date':date, |
184 | + 'state': 'draft', |
185 | + 'line_id': writeoff_lines |
186 | + }) |
187 | + writeoff_line_ids = self.search(cr, uid, [('move_id', '=', writeoff_move_id), ('account_id', '=', account_id)]) |
188 | + if account_id == writeoff_acc_id: |
189 | + writeoff_line_ids = [writeoff_line_ids[1]] |
190 | + |
191 | + if invoice: |
192 | + if (invoice.type == 'out_invoice') or (invoice.type == 'in_invoice'): |
193 | + condition_1 = (account_type == 'payable' and writeoff > 0.0) |
194 | + condition_2 = (account_type == 'receivable' and writeoff < 0.0) |
195 | + else: |
196 | + condition_1 = (account_type == 'payable' and writeoff < 0.0) |
197 | + condition_2 = (account_type == 'receivable' and writeoff > 0.0) |
198 | + if condition_1 or condition_2: |
199 | + writeoff_line_ids = self.search(cr, uid, [('move_id', '=', writeoff_move_id), ('account_id', 'in', (account_id,writeoff_acc_id))]) |
200 | + self.pool.get('account.move.line').write(cr ,uid, writeoff_line_ids, {'name':_('Currency Profit/Loss')}) |
201 | + ids += writeoff_line_ids |
202 | + |
203 | + r_id = self.pool.get('account.move.reconcile').create(cr, uid, { |
204 | + #'name': date, |
205 | + 'type': type, |
206 | + 'line_id': map(lambda x: (4,x,False), ids), |
207 | + 'line_partial_ids': map(lambda x: (3,x,False), ids) |
208 | + }) |
209 | + wf_service = netsvc.LocalService("workflow") |
210 | + # the id of the move.reconcile is written in the move.line (self) by the create method above |
211 | + # because of the way the line_id are defined: (4, x, False) |
212 | + for id in ids: |
213 | + wf_service.trg_trigger(uid, 'account.move.line', id, cr) |
214 | + return r_id |
215 | + |
216 | +account_move_line() |
217 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
218 | |
219 | |
220 | === modified file 'account_invoice_cash_discount/wizard/wizard_discount_reconcile.py' |
221 | --- account_invoice_cash_discount/wizard/wizard_discount_reconcile.py 2010-09-13 09:11:53 +0000 |
222 | +++ account_invoice_cash_discount/wizard/wizard_discount_reconcile.py 2010-09-14 05:41:08 +0000 |
223 | @@ -69,9 +69,13 @@ |
224 | def _trans_rec_reconcile(self, cr, uid, data, context=None): |
225 | pool = pooler.get_pool(cr.dbname) |
226 | account_move_line_obj = pool.get('account.move.line') |
227 | - |
228 | + res_users_obj = pool.get('res.users') |
229 | + invoice_obj = pool.get('account.inovice') |
230 | + |
231 | form = data['form'] |
232 | account_id = form.get('writeoff_acc_id', False) or form.get('discount_acc_id', False) |
233 | + company_currecy_id = res_users_obj.browse(cr, uid, uid, context=context).company_id.currency_id.id |
234 | + invoice_currecy_id = account_move_line_obj.browse(cr, uid, data['id'], context=context).invoice.currency_id.id |
235 | context['date_p'] = form.get('date_p', False) |
236 | date = False |
237 | if context['date_p']: |
238 | @@ -80,7 +84,9 @@ |
239 | period_id = False |
240 | if len(ids): |
241 | period_id = ids[0] |
242 | - |
243 | + |
244 | + context['company_currency_id'] = company_currecy_id |
245 | + context['currency_id'] = invoice_currecy_id |
246 | journal_id = form.get('journal_id', False) |
247 | context['comment'] = form.get('comment', False) |
248 | context['analytic_id'] = form.get('analytic_id', False) |
249 | |
250 | === modified file 'account_payment_discount_extension/__terp__.py' |
251 | --- account_payment_discount_extension/__terp__.py 2010-08-20 12:17:29 +0000 |
252 | +++ account_payment_discount_extension/__terp__.py 2010-09-14 05:41:08 +0000 |
253 | @@ -35,6 +35,7 @@ |
254 | "update_xml" : [ |
255 | "account_payment_disocunt_wizard.xml", |
256 | "account_payment_discount_view.xml", |
257 | + "account_payment_discount_data.xml", |
258 | ], |
259 | "active": False, |
260 | "installable": True, |
261 | |
262 | === modified file 'account_payment_discount_extension/account_payment_discount.py' |
263 | --- account_payment_discount_extension/account_payment_discount.py 2010-09-20 14:25:34 +0000 |
264 | +++ account_payment_discount_extension/account_payment_discount.py 2010-09-14 05:41:08 +0000 |
265 | @@ -25,7 +25,7 @@ |
266 | import time |
267 | from datetime import datetime |
268 | from dateutil.relativedelta import relativedelta |
269 | - |
270 | +from mx import DateTime |
271 | |
272 | class payment_order(osv.osv): |
273 | _inherit='payment.order' |
274 | @@ -39,6 +39,7 @@ |
275 | _columns={ |
276 | 'next_payment_date': fields.date('Next Payment Date', states={'open':[('readonly',True)],'close':[('readonly',True)]},), |
277 | } |
278 | + |
279 | def action_date_assign(self, cr, uid, ids, *args): |
280 | data = super(account_invoice,self).action_date_assign(cr, uid, ids, *args) |
281 | for inv in self.browse(cr, uid, ids): |
282 | @@ -48,7 +49,27 @@ |
283 | delay = payment_data[0].delay |
284 | self.write(cr, uid, [inv.id], {'next_payment_date':(datetime.now() + relativedelta(days=delay)).strftime('%Y-%m-%d')}) |
285 | return data |
286 | + |
287 | + def _next_date(self, cr, uid, ids, context=None): |
288 | + payment_term_obj = self.pool.get('account.payment.term') |
289 | + current_date = datetime.now().strftime('%Y-%m-%d') |
290 | + ids = self.search(cr, uid, [('state','=','open')]) |
291 | + for id in ids: |
292 | + invoice_data = self.browse(cr, uid, id, context=context) |
293 | + next_pay_date = invoice_data.next_payment_date |
294 | + payment_data = payment_term_obj.browse(cr, uid, invoice_data.payment_term.id) |
295 | + if next_pay_date: |
296 | + if next_pay_date < current_date: |
297 | + for dis_line in payment_data.cash_discount_ids: |
298 | + discount_date = (DateTime.strptime(invoice_data.date_invoice, '%Y-%m-%d') + DateTime.RelativeDateTime(days=dis_line.delay)).strftime('%Y-%m-%d') |
299 | + if discount_date > current_date: |
300 | + self.write(cr, uid, [id], {'next_payment_date':discount_date}) |
301 | + break |
302 | + return True |
303 | |
304 | + def check_next_date(self, cr, uid, ids=[], context=None): |
305 | + self._next_date(cr, uid, ids, context=context) |
306 | + |
307 | def copy(self, cr, uid, id, default=None, context=None): |
308 | if default is None: |
309 | default = {} |
310 | |
311 | === added file 'account_payment_discount_extension/account_payment_discount_data.xml' |
312 | --- account_payment_discount_extension/account_payment_discount_data.xml 1970-01-01 00:00:00 +0000 |
313 | +++ account_payment_discount_extension/account_payment_discount_data.xml 2010-09-14 05:41:08 +0000 |
314 | @@ -0,0 +1,17 @@ |
315 | +<?xml version="1.0" encoding="utf-8"?> |
316 | +<openerp> |
317 | + <data noupdate="1"> |
318 | + |
319 | + <record forcecreate="True" id="ir_cron_discount_action" model="ir.cron"> |
320 | + <field name="name">Next Payment Date</field> |
321 | + <field name="interval_number">1</field> |
322 | + <field name="interval_type">days</field> |
323 | + <field name="numbercall">-1</field> |
324 | + <field eval="False" name="doall"/> |
325 | + <field eval="'account.invoice'" name="model"/> |
326 | + <field eval="'check_next_date'" name="function"/> |
327 | + <field eval="'(False,)'" name="args"/> |
328 | + </record> |
329 | + |
330 | + </data> |
331 | +</openerp> |
332 | |
333 | === modified file 'account_payment_discount_extension/wizard/wizard_payment_discount_order.py' |
334 | --- account_payment_discount_extension/wizard/wizard_payment_discount_order.py 2010-09-20 14:25:59 +0000 |
335 | +++ account_payment_discount_extension/wizard/wizard_payment_discount_order.py 2010-09-14 05:41:08 +0000 |
336 | @@ -27,6 +27,7 @@ |
337 | from datetime import datetime |
338 | from dateutil.relativedelta import relativedelta |
339 | from mx import DateTime |
340 | + |
341 | FORM = UpdateableStr() |
342 | |
343 | FIELDS = { |