mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[MIG] subscription_oca: Migration to 17.0
This commit is contained in:
@@ -101,6 +101,12 @@ Contributors
|
||||
|
||||
- Ilyas <irazor147@gmail.com>
|
||||
|
||||
- `Sygel <https://www.sygel.es>`__:
|
||||
|
||||
- Harald Panten
|
||||
- Valentin Vinagre
|
||||
- Alberto Martínez
|
||||
|
||||
Maintainers
|
||||
-----------
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{
|
||||
"name": "Subscription management",
|
||||
"summary": "Generate recurring invoices.",
|
||||
"version": "16.0.1.0.0",
|
||||
"version": "17.0.1.0.0",
|
||||
"development_status": "Beta",
|
||||
"category": "Subscription Management",
|
||||
"website": "https://github.com/OCA/contract",
|
||||
|
||||
@@ -49,7 +49,7 @@ class SaleOrder(models.Model):
|
||||
rec = self.env["sale.subscription"].create(
|
||||
{
|
||||
"partner_id": self.partner_id.id,
|
||||
"user_id": self._context["uid"],
|
||||
"user_id": self.env.context.get("uid", self.env.uid),
|
||||
"template_id": subscription_tmpl.id,
|
||||
"pricelist_id": self.partner_id.property_product_pricelist.id,
|
||||
"date_start": date.today(),
|
||||
@@ -75,7 +75,7 @@ class SaleOrder(models.Model):
|
||||
return grouped
|
||||
|
||||
def action_confirm(self):
|
||||
res = super(SaleOrder, self).action_confirm()
|
||||
res = super().action_confirm()
|
||||
for record in self:
|
||||
grouped = self.group_subscription_lines()
|
||||
for tmpl, lines in grouped.items():
|
||||
|
||||
@@ -116,11 +116,6 @@ class SaleSubscription(models.Model):
|
||||
group_expand="_read_group_stage_ids",
|
||||
store=True,
|
||||
)
|
||||
stage_str = fields.Char(
|
||||
related="stage_id.name",
|
||||
string="Etapa",
|
||||
store=True,
|
||||
)
|
||||
sale_subscription_line_ids = fields.One2many(
|
||||
comodel_name="sale.subscription.line",
|
||||
inverse_name="sale_subscription_id",
|
||||
@@ -320,22 +315,22 @@ class SaleSubscription(models.Model):
|
||||
invoice = self.create_invoice()
|
||||
if self.template_id.invoicing_mode != "draft":
|
||||
invoice.action_post()
|
||||
if self.template_id.invoicing_mode == "invoice_send":
|
||||
mail_template = self.template_id.invoice_mail_template_id
|
||||
invoice.with_context(force_send=True).message_post_with_template(
|
||||
mail_template.id,
|
||||
composition_mode="comment",
|
||||
email_layout_xmlid="mail.mail_notification_paynow",
|
||||
invoice.with_context(force_send=True)._generate_pdf_and_send_invoice(
|
||||
mail_template
|
||||
)
|
||||
invoice_number = invoice.name
|
||||
message_body = (
|
||||
"<b>%s</b> <a href=# data-oe-model=account.move data-oe-id=%d>%s</a>"
|
||||
% (msg_static, invoice.id, invoice_number)
|
||||
f"<b>{msg_static}</b> "
|
||||
f"<a href=# data-oe-model=account.move data-oe-id={invoice.id}>"
|
||||
f"{invoice_number}"
|
||||
"</a>"
|
||||
)
|
||||
|
||||
if self.template_id.invoicing_mode == "sale_and_invoice":
|
||||
order_id = self.create_sale_order()
|
||||
order_id.action_done()
|
||||
order_id.action_confirm()
|
||||
order_id.action_lock()
|
||||
new_invoice = order_id._create_invoices()
|
||||
new_invoice.action_post()
|
||||
new_invoice.invoice_origin = order_id.name + ", " + self.name
|
||||
@@ -346,7 +341,7 @@ class SaleSubscription(models.Model):
|
||||
)
|
||||
if not invoice_number:
|
||||
invoice_number = _("To validate")
|
||||
message_body = "<b>%s</b> %s" % (msg_static, invoice_number)
|
||||
message_body = f"<b>{msg_static}</b> {invoice_number}"
|
||||
self.calculate_recurring_next_date(self.recurring_next_date)
|
||||
self.message_post(body=message_body)
|
||||
|
||||
@@ -447,8 +442,9 @@ class SaleSubscription(models.Model):
|
||||
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
for values in vals_list:
|
||||
if "recurring_rule_boundary" in values:
|
||||
if not values["recurring_rule_boundary"]:
|
||||
template_id = self.env["sale.subscription.template"].browse(
|
||||
@@ -459,7 +455,9 @@ class SaleSubscription(models.Model):
|
||||
date_start = fields.Date.to_date(values["date_start"])
|
||||
values["date"] = template_id._get_date(date_start)
|
||||
if "date_start" in values and "recurring_next_date" in values:
|
||||
res = self._check_dates(values["date_start"], values["recurring_next_date"])
|
||||
res = self._check_dates(
|
||||
values["date_start"], values["recurring_next_date"]
|
||||
)
|
||||
if res:
|
||||
values["date_start"] = values["recurring_next_date"]
|
||||
values["stage_id"] = (
|
||||
@@ -467,4 +465,4 @@ class SaleSubscription(models.Model):
|
||||
.search([("type", "=", "pre")], order="sequence desc", limit=1)
|
||||
.id
|
||||
)
|
||||
return super(SaleSubscription, self).create(values)
|
||||
return super().create(vals_list)
|
||||
|
||||
@@ -39,6 +39,24 @@ class SaleSubscriptionLine(models.Model):
|
||||
store=True,
|
||||
readonly=False,
|
||||
)
|
||||
price_subtotal = fields.Monetary(
|
||||
string="Subtotal", readonly=True, compute="_compute_subtotal", store=True
|
||||
)
|
||||
price_total = fields.Monetary(
|
||||
string="Total", readonly=True, compute="_compute_subtotal", store=True
|
||||
)
|
||||
amount_tax_line_amount = fields.Float(
|
||||
string="Taxes Amount", compute="_compute_subtotal", store=True
|
||||
)
|
||||
sale_subscription_id = fields.Many2one(
|
||||
comodel_name="sale.subscription", string="Subscription"
|
||||
)
|
||||
company_id = fields.Many2one(
|
||||
related="sale_subscription_id.company_id",
|
||||
string="Company",
|
||||
store=True,
|
||||
index=True,
|
||||
)
|
||||
|
||||
@api.depends("product_id", "price_unit", "product_uom_qty", "discount", "tax_ids")
|
||||
def _compute_subtotal(self):
|
||||
@@ -61,25 +79,6 @@ class SaleSubscriptionLine(models.Model):
|
||||
}
|
||||
)
|
||||
|
||||
price_subtotal = fields.Monetary(
|
||||
string="Subtotal", readonly="True", compute=_compute_subtotal, store=True
|
||||
)
|
||||
price_total = fields.Monetary(
|
||||
string="Total", readonly="True", compute=_compute_subtotal, store=True
|
||||
)
|
||||
amount_tax_line_amount = fields.Float(
|
||||
string="Taxes Amount", compute="_compute_subtotal", store=True
|
||||
)
|
||||
sale_subscription_id = fields.Many2one(
|
||||
comodel_name="sale.subscription", string="Subscription"
|
||||
)
|
||||
company_id = fields.Many2one(
|
||||
related="sale_subscription_id.company_id",
|
||||
string="Company",
|
||||
store=True,
|
||||
index=True,
|
||||
)
|
||||
|
||||
@api.depends("product_id")
|
||||
def _compute_name(self):
|
||||
for record in self:
|
||||
@@ -102,7 +101,7 @@ class SaleSubscriptionLine(models.Model):
|
||||
)
|
||||
# If company_id is set, always filter taxes by the company
|
||||
taxes = line.product_id.taxes_id.filtered(
|
||||
lambda t: t.company_id == line.env.company
|
||||
lambda t: t.company_id == self.env.company
|
||||
)
|
||||
line.tax_ids = fpos.map_tax(taxes)
|
||||
|
||||
|
||||
@@ -2,3 +2,7 @@
|
||||
- Carolina Ferrer \<<carolina@domatix.com>\>
|
||||
- [Ooops404](https://www.ooops404.com):
|
||||
- Ilyas \<<irazor147@gmail.com>\>
|
||||
- [Sygel](https://www.sygel.es):
|
||||
- Harald Panten
|
||||
- Valentin Vinagre
|
||||
- Alberto Martínez
|
||||
|
||||
@@ -450,6 +450,12 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
|
||||
<li>Ilyas <<a class="reference external" href="mailto:irazor147@gmail.com">irazor147@gmail.com</a>></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference external" href="https://www.sygel.es">Sygel</a>:<ul>
|
||||
<li>Harald Panten</li>
|
||||
<li>Valentin Vinagre</li>
|
||||
<li>Alberto Martínez</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
|
||||
@@ -60,10 +60,18 @@ class TestSubscriptionOCA(TransactionCase):
|
||||
"price_include": True,
|
||||
}
|
||||
)
|
||||
cls.tax_0pc = cls.env["account.tax"].create(
|
||||
{
|
||||
"name": "0% Tax",
|
||||
"amount_type": "percent",
|
||||
"amount": 0,
|
||||
}
|
||||
)
|
||||
cls.product_1 = cls.env.ref("product.product_product_1")
|
||||
cls.product_1.subscribable = True
|
||||
cls.product_1.taxes_id = [(6, 0, cls.tax_10pc_incl.ids)]
|
||||
cls.product_2 = cls.env.ref("product.product_product_2")
|
||||
cls.product_2.taxes_id = [(6, 0, cls.tax_0pc.ids)]
|
||||
cls.product_2.subscribable = True
|
||||
|
||||
cls.country = cls.env["res.country"].search([], limit=1)
|
||||
@@ -201,7 +209,6 @@ class TestSubscriptionOCA(TransactionCase):
|
||||
cls.sub_line2.unlink()
|
||||
|
||||
# Pricelists.
|
||||
cls.pricelist_default = cls.env.ref("product.list0")
|
||||
cls.pricelist_l1 = cls._create_price_list("Level 1")
|
||||
cls.pricelist_l2 = cls._create_price_list("Level 2")
|
||||
cls.pricelist_l3 = cls._create_price_list("Level 3")
|
||||
@@ -588,7 +595,13 @@ class TestSubscriptionOCA(TransactionCase):
|
||||
self.pricelist_l3.currency_id = self.env.ref("base.THB")
|
||||
self.sub_line.sale_subscription_id.pricelist_id = self.pricelist_l3
|
||||
res = self.sub_line._get_display_price(self.product_1)
|
||||
self.assertAlmostEqual(int(res), 514)
|
||||
self.assertAlmostEqual(
|
||||
int(res),
|
||||
round(
|
||||
self.product_1.standard_price
|
||||
* self.pricelist_l3.currency_id.rate_ids[:1].company_rate
|
||||
),
|
||||
)
|
||||
self.sub_line.product_uom_qty = 300
|
||||
res = self.sub_line.read(["discount"])
|
||||
self.assertEqual(res[0]["discount"], 0)
|
||||
@@ -608,6 +621,24 @@ class TestSubscriptionOCA(TransactionCase):
|
||||
)
|
||||
|
||||
def _collect_all_sub_test_results(self, subscription):
|
||||
"""Creates the invoice of a subscription and returns its data
|
||||
:param subscription: subscription to invoice
|
||||
:returns: Lists with the following data
|
||||
returns[0]: Created sale order record
|
||||
returns[1]: Created invoice record
|
||||
returns[2]: Type of the action to see a manually created invoice
|
||||
returns[3]: Number of invoices
|
||||
returns[4]: Amount total (wout taxes) of all the invoices
|
||||
returns[5]: Invoices count of the subscription
|
||||
returns[6]: Type of the action to the subscription invoices
|
||||
returns[7]: Sale order count of the subscription
|
||||
returns[8]: Id of the sale order
|
||||
returns[9]: Recurring next date of the subscription
|
||||
returns[10]: Id of the pricelist of the subsciption
|
||||
returns[11]: Fiscal position record of the subscription
|
||||
returns[12]: Type of the wizard action close a subscription
|
||||
returns[13]: Subscription stages
|
||||
"""
|
||||
test_res = []
|
||||
sale_order = subscription.create_sale_order()
|
||||
test_res.append(sale_order)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<field name="subscribable" />
|
||||
<field
|
||||
name="subscription_template_id"
|
||||
attrs="{'invisible': [('subscribable', '=', False)]}"
|
||||
invisible="not subscribable"
|
||||
/>
|
||||
</group>
|
||||
</xpath>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
class="oe_stat_button"
|
||||
icon="fa-recycle"
|
||||
name="action_view_subscription_ids"
|
||||
attrs="{'invisible': [('subscription_ids', '=', False)]}"
|
||||
invisible="not subscription_ids"
|
||||
>
|
||||
<div class="o_form_field o_stat_info">
|
||||
<span class="o_stat_value">
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button
|
||||
name="action_view_subscriptions"
|
||||
attrs="{'invisible': [('subscriptions_count', '=', 0)]}"
|
||||
invisible="subscriptions_count == 0"
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
|
||||
@@ -64,11 +64,11 @@
|
||||
/>
|
||||
<label
|
||||
for="recurring_rule_count"
|
||||
attrs="{'invisible': [('recurring_rule_boundary','=','unlimited')]}"
|
||||
invisible="recurring_rule_boundary == 'unlimited'"
|
||||
/>
|
||||
<div
|
||||
class="o_row "
|
||||
attrs="{'invisible': [('recurring_rule_boundary','=','unlimited')]}"
|
||||
invisible="recurring_rule_boundary == 'unlimited'"
|
||||
>
|
||||
<span class="mr-1">For</span>
|
||||
<field
|
||||
@@ -80,7 +80,8 @@
|
||||
<field name="invoicing_mode" widget="radio" />
|
||||
<field
|
||||
name="invoice_mail_template_id"
|
||||
attrs="{'invisible': [('invoicing_mode','!=','invoice_send')], 'required': [('invoicing_mode', '=', 'invoice_send')]}"
|
||||
invisible="invoicing_mode != 'invoice_send'"
|
||||
required="invoicing_mode == 'invoice_send'"
|
||||
/>
|
||||
</group>
|
||||
<group name="right_group">
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
name="action_close_subscription"
|
||||
type="object"
|
||||
help="A given subscription can be marked as closed when, for example, renewal is not desired."
|
||||
attrs="{'invisible': [('in_progress', '=', False)]}"
|
||||
invisible="not in_progress"
|
||||
/>
|
||||
|
||||
<field
|
||||
@@ -36,7 +36,7 @@
|
||||
<button
|
||||
name="action_view_sale_order_ids"
|
||||
type="object"
|
||||
attrs="{'invisible': [('sale_order_ids_count', '=', 0)]}"
|
||||
invisible="sale_order_ids_count == 0"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
>
|
||||
@@ -48,7 +48,7 @@
|
||||
</button>
|
||||
<button
|
||||
name="action_view_account_invoice_ids"
|
||||
attrs="{'invisible': [('account_invoice_ids_count', '=', 0)]}"
|
||||
invisible="account_invoice_ids_count == 0"
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
@@ -66,7 +66,7 @@
|
||||
name="web_ribbon"
|
||||
text="Archived"
|
||||
bg_color="bg-danger"
|
||||
attrs="{'invisible': [('active', '=', True)]}"
|
||||
invisible="active"
|
||||
/>
|
||||
<div class="oe_title">
|
||||
<h1 class="flex-fill d-flex flex-row">
|
||||
@@ -82,16 +82,10 @@
|
||||
<field name="pricelist_id" />
|
||||
<field
|
||||
name="date_start"
|
||||
attrs="{'readonly':['|',('active','=',False), ('in_progress', '=', True)]}"
|
||||
/>
|
||||
<field
|
||||
name="date"
|
||||
attrs="{'invisible':[('recurring_rule_boundary', '=', True)]}"
|
||||
/>
|
||||
<field
|
||||
name="close_reason_id"
|
||||
attrs="{'invisible': [('active', '=', True)]}"
|
||||
readonly="not active or in_progress"
|
||||
/>
|
||||
<field name="date" invisible="recurring_rule_boundary" />
|
||||
<field name="close_reason_id" invisible="active" />
|
||||
<field name="recurring_rule_boundary" invisible="1" />
|
||||
|
||||
</group>
|
||||
@@ -101,7 +95,7 @@
|
||||
<field name="crm_team_id" />
|
||||
<field
|
||||
name="recurring_next_date"
|
||||
attrs="{'invisible': ['|', ('recurring_next_date', '=', False), ('in_progress', '=', False)]}"
|
||||
invisible="not recurring_next_date or not in_progress"
|
||||
/>
|
||||
<field name="company_id" invisible="1" />
|
||||
<field
|
||||
@@ -126,7 +120,7 @@
|
||||
required="True"
|
||||
widget="section_and_note_text"
|
||||
/>
|
||||
<field name="currency_id" invisible="1" />
|
||||
<field name="currency_id" column_invisible="1" />
|
||||
<field name="product_uom_qty" required="True" />
|
||||
<field name="price_unit" required="True" />
|
||||
<field name="discount" required="True" />
|
||||
@@ -220,7 +214,7 @@
|
||||
<field name="amount_tax" sum="Total Tax" optional="show" />
|
||||
<field name="amount_total" sum="Total" optional="show" />
|
||||
<field name="template_id" optional="show" />
|
||||
<field name="stage_str" optional="show" />
|
||||
<field name="stage_id" optional="show" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user