-
-
Notifications
You must be signed in to change notification settings - Fork 523
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
base: 16.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 ? 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. Propose a better solution 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. Nevermind, don't bother, this will never be merged anyways... |
||
[("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) |
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> |
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.