Skip to content

Commit

Permalink
[IMP]contract: Module split: contract, contract_renewal, contract_lin…
Browse files Browse the repository at this point in the history
…e_successor
  • Loading branch information
manuelregidor committed Oct 28, 2024
1 parent 3468e83 commit 9702eb8
Show file tree
Hide file tree
Showing 65 changed files with 3,213 additions and 1,776 deletions.
8 changes: 7 additions & 1 deletion contract/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Recurring - Contracts Management
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d03061fa09dd38d53cbaf6f7ca79de5ff114d100162c7f7646d6a6f301ad3941
!! source digest: sha256:ee6d7ce08f892d005e2127c6e81e5b0acde4662a40e24db17e55eea58a21f12c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
Expand Down Expand Up @@ -153,6 +153,12 @@ Contributors

- Antoni Marroig <[email protected]>

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

- Manuel Regidor <[email protected]>
- Valentín Vinagre <[email protected]>
- Harald Panten <[email protected]>

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

Expand Down
4 changes: 1 addition & 3 deletions contract/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

{
"name": "Recurring - Contracts Management",
"version": "17.0.1.1.1",
"version": "17.0.1.1.0",
"category": "Contract Management",
"license": "AGPL-3",
"author": "Tecnativa, ACSONE SA/NV, Odoo Community Association (OCA)",
Expand All @@ -27,7 +27,6 @@
"report/report_contract.xml",
"report/contract_views.xml",
"data/contract_cron.xml",
"data/contract_renew_cron.xml",
"data/mail_template.xml",
"data/template_mail_notification.xml",
"data/mail_message_subtype.xml",
Expand All @@ -42,7 +41,6 @@
"views/contract_template.xml",
"views/contract_template_line.xml",
"views/res_partner_view.xml",
"views/res_config_settings.xml",
"views/contract_terminate_reason.xml",
"views/contract_portal_templates.xml",
],
Expand Down
2 changes: 0 additions & 2 deletions contract/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@
from . import account_move
from . import res_partner
from . import contract_tag
from . import res_company
from . import res_config_settings
from . import contract_terminate_reason
13 changes: 3 additions & 10 deletions contract/models/abstract_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,16 @@ class ContractAbstractContract(models.AbstractModel):
def _default_generation_type(self):
return "invoice"

@api.onchange("contract_type")
def _onchange_contract_type(self):
if self.contract_type == "purchase":
self.contract_line_ids.filtered("automatic_price").update(
{"automatic_price": False}
)

@api.depends("contract_type", "company_id")
def _compute_journal_id(self):
AccountJournal = self.env["account.journal"]
for contract in self:
journal_id = False
domain = [
("type", "=", contract.contract_type),
("company_id", "=", contract.company_id.id),
]
journal = AccountJournal.search(domain, limit=1)
if journal:
contract.journal_id = journal.id
else:
contract.journal_id = None
journal_id = journal.id
contract.journal_id = journal_id
26 changes: 6 additions & 20 deletions contract/models/abstract_contract_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class ContractAbstractContractLine(models.AbstractModel):
product_id = fields.Many2one("product.product", string="Product")

name = fields.Text(string="Description", required=True)
quantity = fields.Float(default=1.0, required=True)
quantity = fields.Float(
default=1.0, digits="Product Unit of Measure", required=True
)
product_uom_category_id = fields.Many2one( # Used for domain of field uom_id
comodel_name="uom.category",
related="product_id.uom_id.category_id",
Expand All @@ -43,10 +45,10 @@ class ContractAbstractContractLine(models.AbstractModel):
string="Unit Price",
compute="_compute_price_unit",
inverse="_inverse_price_unit",
digits="Product Price",
)
price_subtotal = fields.Monetary(
compute="_compute_price_subtotal",
string="Sub Total",
compute="_compute_price_subtotal", string="Sub Total", digits="Product Price"
)
discount = fields.Float(
string="Discount (%)",
Expand Down Expand Up @@ -87,23 +89,6 @@ class ContractAbstractContractLine(models.AbstractModel):
)
last_date_invoiced = fields.Date()
is_canceled = fields.Boolean(string="Canceled", default=False)
is_auto_renew = fields.Boolean(string="Auto Renew", default=False)
auto_renew_interval = fields.Integer(
default=1,
string="Renew Every",
help="Renew every (Days/Week/Month/Year)",
)
auto_renew_rule_type = fields.Selection(
[
("daily", "Day(s)"),
("weekly", "Week(s)"),
("monthly", "Month(s)"),
("yearly", "Year(s)"),
],
default="yearly",
string="Renewal type",
help="Specify Interval for automatic renewal.",
)
termination_notice_interval = fields.Integer(
default=1, string="Termination Notice Before"
)
Expand Down Expand Up @@ -136,6 +121,7 @@ class ContractAbstractContractLine(models.AbstractModel):
"- Custom: Depending on the recurrence to be define.",
)
is_recurring_note = fields.Boolean(compute="_compute_is_recurring_note")

company_id = fields.Many2one(related="contract_id.company_id", store=True)

def _set_recurrence_field(self, field):
Expand Down
58 changes: 39 additions & 19 deletions contract/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging

from markupsafe import Markup

from odoo import Command, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.osv import expression
Expand Down Expand Up @@ -101,7 +99,6 @@ class ContractContract(models.Model):
partner_id = fields.Many2one(
comodel_name="res.partner", inverse="_inverse_partner_id", required=True
)

commercial_partner_id = fields.Many2one(
"res.partner",
compute_sudo=True,
Expand Down Expand Up @@ -345,6 +342,13 @@ def _compute_create_invoice_visibility(self):
contract.contract_line_ids.mapped("create_invoice_visibility")
)

@api.onchange("contract_type")
def _onchange_contract_type(self):
if self.contract_type == "purchase":
self.contract_line_ids.filtered("automatic_price").update(
{"automatic_price": False}
)

@api.onchange("contract_template_id")
def _onchange_contract_template_id(self):
"""Update the contract fields with that of the template.
Expand Down Expand Up @@ -402,7 +406,6 @@ def _convert_contract_lines(self, contract):
vals["date_start"] = fields.Date.context_today(contract_line)
vals["recurring_next_date"] = fields.Date.context_today(contract_line)
new_lines += contract_line_model.new(vals)
new_lines._onchange_is_auto_renew()
return new_lines

def _prepare_invoice(self, date_invoice, journal=None):
Expand All @@ -426,13 +429,12 @@ def _prepare_invoice(self, date_invoice, journal=None):
if not journal:
raise ValidationError(
_(
"Please define a %(contract_type)s journal "
"for the company '%(company)s'."
"Please define a {contract_type} journal "
"for the company {company}."
).format(
contract_type=self.contract_type,
company=self.company_id.name or "",
)
% {
"contract_type": self.contract_type,
"company": self.company_id.name or "",
}
)
invoice_type = (
"in_invoice" if self.contract_type == "purchase" else "out_invoice"
Expand Down Expand Up @@ -589,10 +591,19 @@ def recurring_create_invoice(self):
"""
invoices = self._recurring_create_invoice()
for invoice in invoices:
body = Markup(_("Contract manually invoiced: %(invoice_link)s")) % {
"invoice_link": invoice._get_html_link(title=invoice.name)
}
self.message_post(body=body)
self.message_post(
body=_(
"Contract manually invoiced: "
"<a"
' href="#" data-oe-model="{model_name}" '
' data-oe-id="{rec_id}"'
">Invoice"
"</a>"
).format(
model_name=invoice._name,
rec_id=invoice.id,
)
)
return invoices

@api.model
Expand All @@ -613,11 +624,20 @@ def _invoice_followers(self, invoices):
def _add_contract_origin(self, invoices):
for item in self:
for move in invoices & item._get_related_invoices():
body = Markup(_("%(msg)s by contract: %(contract_link)s")) % {
"msg": move._creation_message(),
"contract_link": move._get_html_link(title=item.display_name),
}
move.message_post(body=body)
move.message_post(
body=(
_(
(
"%(msg)s by contract <a href=#"
" data-oe-model=contract.contract"
" data-oe-id=%(contract_id)d>%(contract)s</a>."
),
msg=move._creation_message(),
contract_id=item.id,
contract=item.display_name,
)
)
)

def _recurring_create_invoice(self, date_ref=False):
invoices_values = self._prepare_recurring_invoices_values(date_ref)
Expand Down
Loading

0 comments on commit 9702eb8

Please sign in to comment.