Skip to content

Commit

Permalink
[MIG] subscription_oca: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tisho99 committed Jul 10, 2024
1 parent 0498fed commit 7095a9a
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 48 deletions.
6 changes: 6 additions & 0 deletions subscription_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ Contributors

- Ilyas <[email protected]>

- `Sygel <https://www.sygel.es>`__:

- Harald Panten
- Valentin Vinagre
- Alberto Martínez

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion subscription_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions subscription_oca/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def create_subscription(self, lines, subscription_tmpl):
rec = self.env["sale.subscription"].create(
{
"partner_id": self.partner_id.id,
"user_id": self._context["uid"],
"user_id": self._context.get("uid", self.env.uid),
"template_id": subscription_tmpl.id,
"pricelist_id": self.partner_id.property_product_pricelist.id,
"date_start": date.today(),
Expand All @@ -75,7 +75,7 @@ def group_subscription_lines(self):
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():
Expand Down
31 changes: 13 additions & 18 deletions subscription_oca/models/sale_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ def _read_group_stage_ids(self, stages, domain, order):
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",
Expand Down Expand Up @@ -320,22 +315,22 @@ def generate_invoice(self):
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",
)
mail_template = self.template_id.invoice_mail_template_id
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
Expand All @@ -346,7 +341,7 @@ def generate_invoice(self):
)
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)

Expand Down Expand Up @@ -447,7 +442,7 @@ def write(self, values):

return res

@api.model
@api.model_create_multi
def create(self, values):
if "recurring_rule_boundary" in values:
if not values["recurring_rule_boundary"]:
Expand All @@ -467,4 +462,4 @@ def create(self, values):
.search([("type", "=", "pre")], order="sequence desc", limit=1)
.id
)
return super(SaleSubscription, self).create(values)
return super().create(values)
6 changes: 3 additions & 3 deletions subscription_oca/models/sale_subscription_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def _compute_subtotal(self):
)

price_subtotal = fields.Monetary(
string="Subtotal", readonly="True", compute=_compute_subtotal, store=True
string="Subtotal", readonly=True, compute="_compute_subtotal", store=True
)
price_total = fields.Monetary(
string="Total", readonly="True", compute=_compute_subtotal, store=True
string="Total", readonly=True, compute="_compute_subtotal", store=True
)
amount_tax_line_amount = fields.Float(
string="Taxes Amount", compute="_compute_subtotal", store=True
Expand Down Expand Up @@ -102,7 +102,7 @@ def _compute_tax_ids(self):
)
# 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)

Expand Down
4 changes: 4 additions & 0 deletions subscription_oca/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
- Carolina Ferrer \<<[email protected]>\>
- [Ooops404](https://www.ooops404.com):
- Ilyas \<<[email protected]>\>
- [Sygel](https://www.sygel.es):
- Harald Panten
- Valentin Vinagre
- Alberto Martínez
6 changes: 6 additions & 0 deletions subscription_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Ilyas &lt;<a class="reference external" href="mailto:irazor147&#64;gmail.com">irazor147&#64;gmail.com</a>&gt;</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">
Expand Down
35 changes: 33 additions & 2 deletions subscription_oca/tests/test_subscription_oca.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,18 @@ def setUpClass(cls):
"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)
Expand Down Expand Up @@ -201,7 +209,6 @@ def setUpClass(cls):
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")
Expand Down Expand Up @@ -588,7 +595,13 @@ def test_x_subscription_oca_pricelist_related_2(self):
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)
Expand All @@ -608,6 +621,24 @@ def test_compute_display_name(self):
)

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)
Expand Down
2 changes: 1 addition & 1 deletion subscription_oca/views/product_template_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<field name="subscribable" />
<field
name="subscription_template_id"
attrs="{'invisible': [('subscribable', '=', False)]}"
invisible="not subscribable"
/>
</group>
</xpath>
Expand Down
2 changes: 1 addition & 1 deletion subscription_oca/views/res_partner_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
2 changes: 1 addition & 1 deletion subscription_oca/views/sale_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions subscription_oca/views/sale_subscription_template_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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">
Expand Down
26 changes: 10 additions & 16 deletions subscription_oca/views/sale_subscription_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
>
Expand All @@ -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"
Expand All @@ -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">
Expand All @@ -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>
Expand All @@ -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
Expand All @@ -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" />
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 7095a9a

Please sign in to comment.