Skip to content

Commit

Permalink
Merge pull request #29 from CompassionCH/master
Browse files Browse the repository at this point in the history
Various bug fixes and improvements
  • Loading branch information
ecino committed Mar 2, 2016
2 parents f96926d + edc8881 commit 983f2fb
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 55 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ install:
- pip install xlrd
- git clone https://github.com/CompassionCH/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools -b r2
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- git clone https://github.com/CompassionCH/compassion-modules.git ${HOME}/build/CompassionCH/compassion-modules -b 8.0
- git clone https://github.com/OCA/bank-statement-reconcile.git ${HOME}/build/CompassionCH/bank-statement-reconcile -b 8.0
- git clone https://github.com/OCA/bank-statement-import.git ${HOME}/build/CompassionCH/bank-statement-import -b 8.0
- git clone https://github.com/steveferry/l10n-switzerland.git ${HOME}/build/CompassionCH/l10n-switzerland -b port-statement-import
- git clone https://github.com/OCA/l10n-switzerland.git ${HOME}/build/CompassionCH/l10n-switzerland -b 8.0
- git clone https://github.com/OCA/web.git ${HOME}/build/CompassionCH/web -b 8.0
- git clone https://github.com/CompassionCH/compassion-modules.git ${HOME}/build/CompassionCH/compassion-modules -b 8.0
- git clone https://github.com/OCA/bank-payment.git ${HOME}/build/CompassionCH/bank-payment -b 8.0
- git clone https://github.com/OCA/account-financial-tools.git ${HOME}/build/CompassionCH/account-financial-tools -b 8.0
- git clone https://github.com/OCA/partner-contact.git ${HOME}/build/CompassionCH/partner-contact -b 8.0
- git clone https://github.com/OCA/connector.git ${HOME}/build/CompassionCH/connector -b 8.0
- rm -rf ${HOME}/build/CompassionCH/compassion-modules/sbc_compassion
- rm -rf ${HOME}/build/CompassionCH/compassion-modules/onramp_compassion
- travis_install_nightly

before_script:
Expand Down
3 changes: 1 addition & 2 deletions account_analytic_attribution/data/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
<openerp>
<data noupdate="1">
<function model="account.analytic.default" name="install"/>
</data>
<data>

<!-- Root analytic account used for analytic lines which will be
dispatched -->
<record id="account_analytic_root_to_attribute" model="account.analytic.account">
Expand Down
2 changes: 1 addition & 1 deletion account_reconcile_compassion/data/statement_operation.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<data noupdate="1">


<!--
Expand Down
54 changes: 40 additions & 14 deletions account_reconcile_compassion/model/bank_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from datetime import datetime

from openerp.addons.connector.queue.job import job
from openerp.addons.connector.queue.job import job, related_action
from openerp.addons.connector.session import ConnectorSession


Expand Down Expand Up @@ -81,15 +81,15 @@ def get_move_lines_for_reconciliation(
reverse=True)
return res_sorted

@api.multi
def process_reconciliation(self, mv_line_dicts):
@api.model
def process_reconciliations(self, mv_line_dicts):
""" Launch reconciliation in a job. """
if self.env.context.get('async_mode', True):
session = ConnectorSession.from_env(self.env)
process_reconciliation_job.delay(
session, self._name, self.ids, mv_line_dicts)
process_reconciliations_job.delay(
session, self._name, mv_line_dicts)
else:
self._process_reconciliation(mv_line_dicts)
self._process_reconciliations(mv_line_dicts)

@api.model
def product_id_changed(self, product_id, date):
Expand All @@ -108,8 +108,13 @@ def product_id_changed(self, product_id, date):
##########################################################################
# PRIVATE METHODS #
##########################################################################
@api.model
def _process_reconciliations(self, mv_line_dicts):
super(bank_statement_line, self).process_reconciliations(
mv_line_dicts)

@api.one
def _process_reconciliation(self, mv_line_dicts):
def process_reconciliation(self, mv_line_dicts):
""" Create invoice if product_id is set in move_lines
to be created. """
partner_invoices = dict()
Expand Down Expand Up @@ -163,9 +168,10 @@ def _create_invoice_from_mv_lines(self, mv_line_dicts, invoice=None):
self.statement_id.write({'recurring_invoicer_id': invoicer.id})

# Generate a unique bvr_reference
ref = self.ref
if ref and len(ref) > 27:
ref = mod10r(ref[:26])
if self.ref and len(self.ref) == 27:
ref = self.ref
elif self.ref and len(self.ref) > 27:
ref = mod10r(self.ref[:26])
else:
ref = mod10r((self.date.replace('-', '') + str(
self.statement_id.id) + str(self.id)).ljust(26, '0'))
Expand Down Expand Up @@ -239,7 +245,8 @@ def _create_invoice_from_mv_lines(self, mv_line_dicts, invoice=None):
'quantity': 1,
'uos_id': False,
'product_id': product.id,
'partner_id': self.partner_id.id,
'partner_id': contract.partner_id.id if contract else
self.partner_id.id,
'invoice_id': invoice.id,
# Remove analytic account from bank journal item:
# it is only useful in the invoice journal item
Expand All @@ -255,6 +262,9 @@ def _create_invoice_from_mv_lines(self, mv_line_dicts, invoice=None):
_('Add a Sponsorship'))

self.env['account.invoice.line'].create(inv_line_data)
# Put payer as partner
if contract:
invoice.partner_id = contract.partner_id

invoice.button_compute()
invoice.signal_workflow('invoice_open')
Expand Down Expand Up @@ -289,8 +299,24 @@ def _find_open_invoice(self, mv_line_dicts):
##############################################################################
# CONNECTOR METHODS #
##############################################################################
def related_action_reconciliations(session, job):
line_ids = [arg[0] for arg in job.args[1]]
statement_lines = session.env[job.args[0]].browse(line_ids)
statement_ids = statement_lines.mapped('statement_id').ids
action = {
'name': _("Bank statements"),
'type': 'ir.actions.act_window',
'res_model': 'account.bank.statement',
'view_type': 'form',
'view_mode': 'form,tree',
'res_id': statement_ids[0],
'domain': [('id', 'in', statement_ids)],
}
return action


@job(default_channel='root.reconciliation')
def process_reconciliation_job(session, model_name, line_ids, mv_line_dicts):
@related_action(action=related_action_reconciliations)
def process_reconciliations_job(session, model_name, mv_line_dicts):
"""Job for reconciling bank statment lines."""
statement_lines = session.env[model_name].browse(line_ids)
statement_lines._process_reconciliation(mv_line_dicts)
session.env[model_name]._process_reconciliations(mv_line_dicts)
2 changes: 1 addition & 1 deletion chart_account_compassion/account.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<openerp>
<data>
<data noupdate="1">
<record id="account_type_view" model="account.account.type">
<field name="name">Autre : Vue</field>
<field name="code">view</field>
Expand Down
49 changes: 21 additions & 28 deletions recurring_contract/model/contract_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,18 @@ def write(self, vals):
- Another change method was selected
"""
res = True
# to solve "NotImplementedError: Iteration is not allowed" error
# Any of these modifications implies generate and validate invoices
generate_again = ('advance_billing_months' in vals or
'recurring_value' in vals or
'recurring_unit' in vals)

for group in self:

# Check if group has an next_invoice_date
if not group.next_invoice_date:
res = super(contract_group, self).write(vals) and res
break
if not group.next_invoice_date or 'next_invoice_date' in vals:
res = super(contract_group, group).write(vals) and res
continue

# Get the method to apply changes
change_method = vals.get('change_method', group.change_method)
change_method = getattr(self, change_method)

res = super(contract_group, self).write(vals) & res

if generate_again:
change_method()
change_method = getattr(group, change_method)

if generate_again:
invoicer = self.generate_invoices()
self.validate_invoices(invoicer)
res = super(contract_group, group).write(vals) & res
change_method()

return res

Expand Down Expand Up @@ -152,9 +139,9 @@ def clean_invoices(self):
"""
if self.env.context.get('async_mode', True):
session = ConnectorSession.from_env(self.env)
clean_invoices_job.delay(session, self._name, self.ids)
clean_generate_job.delay(session, self._name, self.ids)
else:
self._clean_invoices()
self._clean_generate_invoices()
return True

def do_nothing(self):
Expand Down Expand Up @@ -194,6 +181,9 @@ def _generate_invoices(self, invoicer=None):
Create an invoice per contract group per date.
"""
logger.info("Invoice generation started.")
if invoicer is None:
invoicer = self.env['recurring.invoicer'].create(
{'source': self._name})
inv_obj = self.env['account.invoice']
journal_obj = self.env['account.journal']
gen_states = self._get_gen_states()
Expand Down Expand Up @@ -237,7 +227,7 @@ def _generate_invoices(self, invoicer=None):
return invoicer

@api.multi
def _clean_invoices(self):
def _clean_generate_invoices(self):
""" Change method which cancels generated invoices and rewinds
the next_invoice_date of contracts, so that new invoices can be
generated taking into consideration the modifications of the
Expand All @@ -246,13 +236,16 @@ def _clean_invoices(self):
res = self.env['account.invoice']
for group in self:
since_date = datetime.today()
if self.last_paid_invoice_date:
if group.last_paid_invoice_date:
last_paid_invoice_date = datetime.strptime(
self.last_paid_invoice_date, DF)
group.last_paid_invoice_date, DF)
since_date = max(since_date, last_paid_invoice_date)
res += self.contract_ids._clean_invoices(
res += group.contract_ids._clean_invoices(
since_date=since_date.strftime(DF))
self.contract_ids.rewind_next_invoice_date()
group.contract_ids.rewind_next_invoice_date()
# Generate again invoices
invoicer = self._generate_invoices()
self.validate_invoices(invoicer)
return res

@api.multi
Expand Down Expand Up @@ -348,7 +341,7 @@ def generate_invoices_job(session, model_name, group_ids, invoicer_id):


@job(default_channel='root.recurring_invoicer')
def clean_invoices_job(session, model_name, group_ids):
def clean_generate_job(session, model_name, group_ids):
"""Job for cleaning invoices of a contract group."""
groups = session.env[model_name].browse(group_ids)
groups._clean_invoices()
groups._clean_generate_invoices()
24 changes: 22 additions & 2 deletions recurring_contract/model/recurring_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class recurring_contract(models.Model):
track_visibility="onchange", store=True)
payment_term_id = fields.Many2one(
'account.payment.term', string='Payment Term',
related='group_id.payment_term_id', readonly=True, store=True)
related='group_id.payment_term_id', readonly=True, store=True)
nb_invoices = fields.Integer(compute='_count_invoices')

##########################################################################
# FIELDS METHODS #
Expand All @@ -138,7 +139,12 @@ def _check_unique_reference(self):
if self.reference in ref_lst:
raise exceptions.ValidationError(
_('Error: Reference should be unique'))
return True
return True

def _count_invoices(self):
for contract in self:
contract.nb_invoices = len(
contract.mapped('invoice_line_ids.invoice_id'))

##########################################################################
# ORM METHODS #
Expand Down Expand Up @@ -263,6 +269,20 @@ def button_generate_invoices(self):
return self.mapped('group_id').with_context(
async_mode=False).button_generate_invoices()

@api.multi
def open_invoices(self):
self.ensure_one()
invoice_ids = self.mapped('invoice_line_ids.invoice_id').ids
return {
'name': _('Contract invoices'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.invoice',
'domain': [('id', 'in', invoice_ids)],
'target': 'current',
}

##########################################################################
# WORKFLOW METHODS #
##########################################################################
Expand Down
11 changes: 10 additions & 1 deletion recurring_contract/view/recurring_contract_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@
</header>
<sheet>
<div class="oe_right oe_button_box">
<button name="button_generate_invoices" type='object' string="Generate invoices" states="active"/>
<!-- to change icone of smart button, you can find tag here:http://fortawesome.github.io/Font-Awesome/icons/ -->
<button name="button_generate_invoices" type='object' groups="account.group_account_user" class="oe_inline oe_stat_button" icon="fa-refresh" string="Generate invoices" states="active" />
<button name="open_invoices" type="object" groups="account.group_account_user" class="oe_inline oe_stat_button" icon="fa-pencil-square-o">
<div>
<strong>
<field name="nb_invoices"/>
</strong>
<br/>Invoices
</div>
</button>
</div>

<div class="oe_title">
Expand Down
6 changes: 2 additions & 4 deletions recurring_contract/wizard/recurring_invoicer_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class recurring_invoicer_wizard(models.TransientModel):
'''
_name = 'recurring.invoicer.wizard'

invoice_ids = fields.One2many(
'account.invoice', 'recurring_invoicer_id',
_('Generated invoices'), readonly=True)
generation_date = fields.Date(_('Generation date'), readonly=True)

@api.multi
Expand All @@ -31,7 +28,8 @@ def generate(self):
contract_groups = self.env['recurring.contract.group'].search([])
invoicer = recurring_invoicer_obj.create({'source': self._name})

contract_groups.generate_invoices(invoicer)
contract_groups.with_context(async_mode=False).generate_invoices(
invoicer)

return {
'name': 'recurring.invoicer.form',
Expand Down

0 comments on commit 983f2fb

Please sign in to comment.