-
-
Notifications
You must be signed in to change notification settings - Fork 519
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][IMP] subscription_oca: Various improvements #1058
Open
tarteo
wants to merge
2
commits into
OCA:16.0
Choose a base branch
from
tarteo:16-imp-subscription_oca
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,21 +142,22 @@ def cron_subscription_management(self): | |
for subscription in self.search([]): | ||
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: | ||
subscription.action_start_subscription() | ||
subscription.generate_invoice() | ||
elif ( | ||
subscription.date_start <= today and subscription.stage_id.type == "pre" | ||
): | ||
subscription.action_start_subscription() | ||
subscription.generate_invoice() | ||
|
||
@api.depends("sale_subscription_line_ids") | ||
def _compute_total(self): | ||
|
@@ -239,7 +240,6 @@ def action_start_subscription(self): | |
self.stage_id = in_progress_stage | ||
|
||
def action_close_subscription(self): | ||
self.recurring_next_date = False | ||
return { | ||
"view_type": "form", | ||
"view_mode": "form", | ||
|
@@ -249,6 +249,16 @@ def action_close_subscription(self): | |
"res_id": False, | ||
} | ||
|
||
def close_subscription(self, close_reason_id=False): | ||
self.ensure_one() | ||
self.recurring_next_date = False | ||
closed_stage = self.env["sale.subscription.stage"].search( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really like selection with a limit=1. Is there a mean to restrict stage selection in a better way ? |
||
[("type", "=", "post")], limit=1 | ||
) | ||
self.close_reason_id = close_reason_id | ||
if self.stage_id != closed_stage: | ||
self.stage_id = closed_stage | ||
|
||
def _prepare_sale_order(self, line_ids=False): | ||
self.ensure_one() | ||
return { | ||
|
@@ -271,6 +281,7 @@ def _prepare_account_move(self, line_ids): | |
"invoice_user_id": self.user_id.id, | ||
"partner_bank_id": self.company_id.partner_id.bank_ids[:1].id, | ||
"invoice_line_ids": line_ids, | ||
"subscription_id": self.id, | ||
} | ||
if self.journal_id: | ||
values["journal_id"] = self.journal_id.id | ||
|
@@ -294,7 +305,6 @@ def create_invoice(self): | |
.with_context(default_move_type="out_invoice", journal_type="sale") | ||
.create(invoice_values) | ||
) | ||
self.write({"invoice_ids": [(4, invoice_id.id)]}) | ||
return invoice_id | ||
|
||
def create_sale_order(self): | ||
|
@@ -464,7 +474,7 @@ def create(self, values): | |
values["date_start"] = values["recurring_next_date"] | ||
values["stage_id"] = ( | ||
self.env["sale.subscription.stage"] | ||
.search([("type", "=", "pre")], order="sequence desc", limit=1) | ||
.search([("type", "=", "draft")], order="sequence desc", limit=1) | ||
.id | ||
) | ||
return super(SaleSubscription, self).create(values) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" ?> | ||
<odoo> | ||
<record id="view_move_form" model="ir.ui.view"> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_move_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//div[@name='button_box']" position="inside"> | ||
<field name="subscription_id" invisible="1" /> | ||
<button | ||
name="action_open_subscription" | ||
type="object" | ||
class="oe_stat_button" | ||
icon="fa-calendar" | ||
string="Subscription" | ||
attrs="{'invisible': [('subscription_id', '=', False)]}" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
action = self.env["ir.actions.act_window"]._for_xml_id("subscription_oca.sale_subscription_action")
instead.