mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[FIX] account_analytic_analysis_recurring: #START# and #END# set correctly
[IMP] Some conventions
This commit is contained in:
@@ -23,15 +23,14 @@ import datetime
|
||||
import logging
|
||||
import time
|
||||
|
||||
from openerp.osv import osv, fields
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.tools.translate import _
|
||||
|
||||
from openerp.addons.decimal_precision import decimal_precision as dp
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class account_analytic_invoice_line(osv.osv):
|
||||
class AccountAnalyticInvoiceLine(orm.Model):
|
||||
_name = "account.analytic.invoice.line"
|
||||
|
||||
def _amount_line(
|
||||
@@ -104,7 +103,7 @@ class account_analytic_invoice_line(osv.osv):
|
||||
return res_final
|
||||
|
||||
|
||||
class account_analytic_account(osv.osv):
|
||||
class AccountAnalyticAccount(orm.Model):
|
||||
_name = "account.analytic.account"
|
||||
_inherit = "account.analytic.account"
|
||||
|
||||
@@ -132,6 +131,13 @@ class account_analytic_account(osv.osv):
|
||||
'recurring_rule_type': 'monthly'
|
||||
}
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
# Reset next invoice date
|
||||
default['recurring_next_date'] = \
|
||||
self._defaults['recurring_next_date']()
|
||||
return super(AccountAnalyticAccount, self).copy(
|
||||
cr, uid, id, default=default, context=context)
|
||||
|
||||
def onchange_recurring_invoices(
|
||||
self, cr, uid, ids, recurring_invoices,
|
||||
date_start=False, context=None):
|
||||
@@ -147,9 +153,8 @@ class account_analytic_account(osv.osv):
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
fpos_obj = self.pool.get('account.fiscal.position')
|
||||
lang_obj = self.pool.get('res.lang')
|
||||
|
||||
if not contract.partner_id:
|
||||
raise osv.except_osv(
|
||||
raise orm.except_orm(
|
||||
_('No Customer Defined!'),
|
||||
_("You must first select a Customer for Contract %s!") %
|
||||
contract.name)
|
||||
@@ -161,7 +166,7 @@ class account_analytic_account(osv.osv):
|
||||
('company_id', '=', contract.company_id.id or False)],
|
||||
limit=1)
|
||||
if not journal_ids:
|
||||
raise osv.except_osv(
|
||||
raise orm.except_orm(
|
||||
_('Error!'),
|
||||
_('Please define a sale journal for the company "%s".') %
|
||||
(contract.company_id.name or '', ))
|
||||
@@ -209,42 +214,35 @@ class account_analytic_account(osv.osv):
|
||||
'invoice_id': invoice_id,
|
||||
'invoice_line_tax_id': [(6, 0, tax_id)],
|
||||
}
|
||||
self.pool.get('account.invoice.line').create(
|
||||
self.pool['account.invoice.line'].create(
|
||||
cr, uid, invoice_line_vals, context=context)
|
||||
|
||||
inv_obj.button_compute(cr, uid, [invoice_id], context=context)
|
||||
return invoice_id
|
||||
|
||||
def recurring_create_invoice(self, cr, uid, automatic=False, context=None):
|
||||
context = context or {}
|
||||
if context is None:
|
||||
context = {}
|
||||
current_date = time.strftime('%Y-%m-%d')
|
||||
|
||||
contract_ids = self.search(
|
||||
cr, uid,
|
||||
[('recurring_next_date', '<=', current_date),
|
||||
('state', '=', 'open'),
|
||||
('recurring_invoices', '=', True)])
|
||||
for contract in self.browse(cr, uid, contract_ids, context=context):
|
||||
|
||||
next_date = datetime.datetime.strptime(
|
||||
contract.recurring_next_date or current_date, "%Y-%m-%d")
|
||||
interval = contract.recurring_interval
|
||||
old_date = next_date
|
||||
if contract.recurring_rule_type == 'daily':
|
||||
old_date = next_date-relativedelta(days=+interval)
|
||||
new_date = next_date+relativedelta(days=+interval)
|
||||
new_date = next_date + relativedelta(days=+interval)
|
||||
elif contract.recurring_rule_type == 'weekly':
|
||||
old_date = next_date-relativedelta(weeks=+interval)
|
||||
new_date = next_date+relativedelta(weeks=+interval)
|
||||
new_date = next_date + relativedelta(weeks=+interval)
|
||||
else:
|
||||
old_date = next_date+relativedelta(months=+interval)
|
||||
new_date = next_date+relativedelta(months=+interval)
|
||||
|
||||
new_date = next_date + relativedelta(months=+interval)
|
||||
context['old_date'] = old_date
|
||||
context['next_date'] = datetime.datetime.strptime(
|
||||
contract.recurring_next_date or current_date, "%Y-%m-%d")
|
||||
context['next_date'] = new_date
|
||||
self._prepare_invoice(
|
||||
cr, uid, contract, context=context)
|
||||
|
||||
self.write(
|
||||
cr, uid, [contract.id],
|
||||
{'recurring_next_date': new_date.strftime('%Y-%m-%d')},
|
||||
|
||||
Reference in New Issue
Block a user