Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] FIX subscription_oca in multi company + allow to invoice with recurring_next_date before today #1167

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions subscription_oca/models/sale_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,23 @@ def _read_group_stage_ids(self, stages, domain, order):

def cron_subscription_management(self):
today = date.today()
for subscription in self.search([]):
for subscription in self.search([], order="recurring_next_date asc"):
subscription = subscription.with_company(subscription.company_id)
if subscription.in_progress:
if (
subscription.recurring_next_date == today
subscription.recurring_next_date <= today
and subscription.sale_subscription_line_ids
):
try:
subscription.generate_invoice()
except Exception:
logger.exception("Error on subscription invoice generate")
if not subscription.recurring_rule_boundary:
if subscription.date == today:
if subscription.date <= today:
subscription.action_close_subscription()

else:
if subscription.date_start == today:
if subscription.date_start <= today:
subscription.action_start_subscription()
subscription.generate_invoice()

Expand Down
39 changes: 39 additions & 0 deletions subscription_oca/views/sale_subscription_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,50 @@
<field name="arch" type="xml">
<search>
<field name="to_renew" />
<field name="name" />
<field name="partner_id" />
<field name="template_id" />
<field name="user_id" />
<field name="date_start" />
<field name="recurring_next_date" />
<field name="stage_id" />
<filter
string="Pending subscriptions"
name="pendingsubs"
domain="[('to_renew','=', True)]"
/>
<separator />
<filter
name="month_recurring_next_date"
string="Next invoice date"
date="recurring_next_date"
/>
<group expand="0" string="Group By">
<filter
string="Partner"
name="groupby_partner_id"
domain="[]"
context="{'group_by': 'partner_id'}"
/>
<filter
string="Next invoice date"
name="groupby_recurring_next_date"
domain="[]"
context="{'group_by': 'recurring_next_date'}"
/>
<filter
string="Commercial agent"
name="groupby_user_id"
domain="[]"
context="{'group_by': 'user_id'}"
/>
<filter
string="Stage"
name="groupby_stage_id"
domain="[]"
context="{'group_by': 'stage_id'}"
/>
</group>
</search>
</field>
</record>
Expand Down
Loading