Skip to content
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
3 changes: 2 additions & 1 deletion subscription_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Subscription management
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ab6023e140886cb5c4fe2d8e969d404ab4a58de4701d6b906c424c9521d1b5d1
!! source digest: sha256:97968d8f4c76218854462c7fe550017397400003fcc8f1a6417d88212d79917b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -102,6 +102,7 @@ Contributors

- Carlos Martínez <carlos@domatix.com>
- Carolina Ferrer <carolina@domatix.com>
- Alejandro Roser <aleajndro@domatix.com>
- `Ooops404 <https://www.ooops404.com>`__:

- Ilyas <irazor147@gmail.com>
Expand Down
2 changes: 2 additions & 0 deletions subscription_oca/models/sale_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def _compute_total(self):
for record in self:
recurring_total = amount_tax = 0.0
for order_line in record.sale_subscription_line_ids:
if order_line.display_type:
continue
recurring_total += order_line.price_subtotal
amount_tax += order_line.amount_tax_line_amount
record.update(
Expand Down
42 changes: 40 additions & 2 deletions subscription_oca/models/sale_subscription_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class SaleSubscriptionLine(models.Model):
store=True,
readonly=False,
)
display_type = fields.Selection(
selection=[
("line_section", "Section"),
("line_note", "Note"),
],
default=False)
price_subtotal = fields.Monetary(
string="Subtotal", readonly=True, compute="_compute_subtotal", store=True
)
Expand All @@ -58,10 +64,20 @@ class SaleSubscriptionLine(models.Model):
store=True,
index=True,
)

sequence = fields.Integer(
string="Sequence",
default=10,
)
@api.depends("product_id", "price_unit", "product_uom_qty", "discount", "tax_ids")
def _compute_subtotal(self):
for record in self:
if record.display_type:
record.update({
"amount_tax_line_amount": 0.0,
"price_total": 0.0,
"price_subtotal": 0.0,
})
continue
price = record.price_unit * (1 - (record.discount or 0.0) / 100.0)
taxes = record.tax_ids.compute_all(
price,
Expand All @@ -83,6 +99,8 @@ def _compute_subtotal(self):
@api.depends("product_id")
def _compute_name(self):
for record in self:
if record.display_type:
continue
if not record.product_id:
record.name = False
lang = get_lang(self.env, record.sale_subscription_id.partner_id.lang).code
Expand All @@ -94,6 +112,9 @@ def _compute_name(self):
@api.depends("product_id", "sale_subscription_id.fiscal_position_id")
def _compute_tax_ids(self):
for line in self:
if line.display_type:
line.tax_ids = False
continue
fpos = (
line.sale_subscription_id.fiscal_position_id
or line.sale_subscription_id.fiscal_position_id._get_fiscal_position(
Expand All @@ -113,6 +134,9 @@ def _compute_tax_ids(self):
)
def _compute_price_unit(self):
for record in self:
if record.display_type:
record.price_unit = 0.0
continue
if not record.product_id:
continue
if (
Expand Down Expand Up @@ -146,6 +170,9 @@ def _compute_price_unit(self):
)
def _compute_discount(self):
for record in self:
if record.display_type:
record.discount = 0.0
continue
if not (
record.product_id
and record.product_id.uom_id
Expand Down Expand Up @@ -281,8 +308,14 @@ def _get_display_price(self, product):
)
return max(base_price, final_price)


def _prepare_sale_order_line(self):
self.ensure_one()
if self.display_type:
return {
'display_type': self.display_type,
'name': self.name,
}
return {
"product_id": self.product_id.id,
"name": self.name,
Expand All @@ -294,13 +327,18 @@ def _prepare_sale_order_line(self):
"product_uom": self.product_id.uom_id.id,
"analytic_distribution": self.analytic_distribution,
}

def _prepare_account_move_line(self):
self.ensure_one()
account = (
self.product_id.property_account_income_id
or self.product_id.categ_id.property_account_income_categ_id
)
if self.display_type:
return {
'display_type': self.display_type,
'name': self.name,
}
return {
"product_id": self.product_id.id,
"name": self.name,
Expand Down
1 change: 1 addition & 0 deletions subscription_oca/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- Carlos Martínez \<<carlos@domatix.com>\>
- Carolina Ferrer \<<carolina@domatix.com>\>
- Alejandro Roser \<<aleajndro@domatix.com>\>
- [Ooops404](https://www.ooops404.com):
- Ilyas \<<irazor147@gmail.com>\>
- [Sygel](https://www.sygel.es):
Expand Down
4 changes: 3 additions & 1 deletion subscription_oca/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ To make a subscription:
invoice even if the subscription template has the *Sale Order &
Invoice* option selected, because the *Invoicing mode* option is
triggered through the cron job.
5. The cron job will also end the subscription if its end date has been
5. You can create sections and notes in the subscription invoice, they will
be passed to the generated invoices retaining the format.
6. The cron job will also end the subscription if its end date has been
reached.

To create subscriptions with the sale of a product:
Expand Down
3 changes: 2 additions & 1 deletion subscription_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ <h1>Subscription management</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ab6023e140886cb5c4fe2d8e969d404ab4a58de4701d6b906c424c9521d1b5d1
!! source digest: sha256:97968d8f4c76218854462c7fe550017397400003fcc8f1a6417d88212d79917b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/contract/tree/18.0/subscription_oca"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/contract-18-0/contract-18-0-subscription_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/contract&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows creating subscriptions that generate recurring
Expand Down Expand Up @@ -452,6 +452,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<ul class="simple">
<li>Carlos Martínez &lt;<a class="reference external" href="mailto:carlos&#64;domatix.com">carlos&#64;domatix.com</a>&gt;</li>
<li>Carolina Ferrer &lt;<a class="reference external" href="mailto:carolina&#64;domatix.com">carolina&#64;domatix.com</a>&gt;</li>
<li>Alejandro Roser &lt;<a class="reference external" href="mailto:aleajndro&#64;domatix.com">aleajndro&#64;domatix.com</a>&gt;</li>
<li><a class="reference external" href="https://www.ooops404.com">Ooops404</a>:<ul>
<li>Ilyas &lt;<a class="reference external" href="mailto:irazor147&#64;gmail.com">irazor147&#64;gmail.com</a>&gt;</li>
</ul>
Expand Down
65 changes: 55 additions & 10 deletions subscription_oca/views/sale_subscription_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,57 @@
string="Subscription lines"
name="subscription_lines_page"
>
<field name="sale_subscription_line_ids">
<field name="sale_subscription_line_ids"
widget="sol_o2m"
mode="list"
>
<form>
<field name="display_type" invisible="1"/>
<field name="sequence" invisible="1"/>
<group>
<group invisible="display_type">
<field name="analytic_distribution"
widget="analytic_distribution"
groups="analytic.group_analytic_accounting"
options="{'product_field': 'product_id', 'business_domain': 'sale_order'}"/>
</group>
</group>
<label for="name" string="Description" invisible="display_type"/>
<label for="name" string="Section Name (eg. Products, Services)" invisible="display_type != 'line_section'"/>
<label for="name" string="Note" invisible="display_type != 'line_note'"/>
<field name="name"/>
<field name="company_id" invisible="1"/>
</form>
<list editable="bottom">
<field name="currency_id" column_invisible="1" />
<field name="product_id" required="True" />
<control>
<create name="add_product_control" string="Add a product"/>
<create name="add_section_control" string="Add a section" context="{'default_display_type': 'line_section'}"/>
<create name="add_note_control" string="Add a note" context="{'default_display_type': 'line_note'}"/>
</control>
<field name="sequence" widget="handle"/>
<field name="display_type" column_invisible="1"/>
<field name="currency_id" column_invisible="1"/>
<field
name="product_id"
string="Product"
required="not display_type"
context="{
'partner_id': parent.partner_id,
'quantity': product_uom_qty,
'pricelist': parent.pricelist_id,
'company_id': parent.company_id,
'default_lst_price': price_unit,
}"
options="{
'no_open': True,
}"
optional="show"
domain="[('sale_ok', '=', True)]"
widget="sol_product_many2one"
placeholder="Type to find a product..."/>
<field
name="name"
required="True"
widget="section_and_note_text"
widget="sol_text"
/>
<field
name="analytic_distribution"
Expand All @@ -119,18 +162,20 @@
groups="analytic.group_analytic_accounting"
options="{'product_field': 'product_id', 'business_domain': 'sale_order'}"
/>
<field name="product_uom_qty" required="True" />
<field name="price_unit" required="True" />
<field name="discount" required="True" />
<field name="product_uom_qty" required="not display_type" />
<field name="price_unit" required="not display_type" />
<field name="discount" required="not display_type" />
<field name="tax_ids" widget="many2many_tags" />
<field
name="price_subtotal"
options="{'currency_field': 'currency_id'}"
/>
string="Amount"/>
<field
name="price_total"
options="{'currency_field': 'currency_id'}"
/>
optional="hide"
string="Tax Incl."/>
<field name="company_id" column_invisible="1"/>
</list>
</field>
<group
Expand Down