Skip to content

Commit

Permalink
[MIG] Migrated contract module to V 16.0 - Need to check how to proce…
Browse files Browse the repository at this point in the history
…ed with account analytic tag
  • Loading branch information
wpichler committed Oct 25, 2022
1 parent 49bc702 commit 5a8fc96
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 259 deletions.
2 changes: 1 addition & 1 deletion contract/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

{
"name": "Recurring - Contracts Management",
"version": "15.0.1.5.2",
"version": "16.0.1.0.0",
"category": "Contract Management",
"license": "AGPL-3",
"author": "Tecnativa, ACSONE SA/NV, Odoo Community Association (OCA)",
Expand Down
19 changes: 0 additions & 19 deletions contract/data/template_mail_notification.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
<?xml version="1.0" ?>
<odoo>
<template
id="mail_notification_contract"
inherit_id="mail.mail_notification_paynow"
primary="True"
>
<xpath expr="//t[@t-out='message.body']" position="after">
<t t-raw="0" />
<t t-if="record._name == 'contract.contract'">
<t
t-set="share_url"
t-value="record._get_share_url(redirect=True, signup_partner=True, share_token=True)"
/>
<t
t-set="access_url"
t-value="is_online and share_url and base_url + share_url or ''"
/>
</t>
</xpath>
</template>
<template id="template_contract_modification" name="Contract Modification">
<t t-call="contract.mail_notification_contract">
<table border="1" align="center">
Expand Down
141 changes: 0 additions & 141 deletions contract/migrations/15.0.1.0.0/noupdate_changes.xml

This file was deleted.

17 changes: 0 additions & 17 deletions contract/migrations/15.0.1.0.0/post-migration.py

This file was deleted.

6 changes: 5 additions & 1 deletion contract/models/abstract_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ContractAbstractContract(models.AbstractModel):
_inherit = "contract.recurrency.basic.mixin"
_name = "contract.abstract.contract"
_description = "Abstract Recurring Contract"
_check_company_auto = True

# These fields will not be synced to the contract
NO_SYNC = ["name", "partner_id", "company_id"]
Expand All @@ -31,11 +32,12 @@ class ContractAbstractContract(models.AbstractModel):
journal_id = fields.Many2one(
comodel_name="account.journal",
string="Journal",
domain="[('type', '=', contract_type)," "('company_id', '=', company_id)]",
domain="[('type', '=', contract_type)]",
compute="_compute_journal_id",
store=True,
readonly=False,
index=True,
check_company=True,
)
company_id = fields.Many2one(
"res.company",
Expand Down Expand Up @@ -80,3 +82,5 @@ def _compute_journal_id(self):
journal = AccountJournal.search(domain, limit=1)
if journal:
contract.journal_id = journal.id
else:
contract.journal_id = None
28 changes: 17 additions & 11 deletions contract/models/abstract_contract_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def _compute_price_unit(self):
"old_date", fields.Date.context_today(line)
),
)
line.price_unit = product.price
line.price_unit = pricelist._get_product_price(product, quantity=1)
else:
line.price_unit = line.specific_price

Expand Down Expand Up @@ -248,14 +248,20 @@ def _onchange_product_id(self):

date = self.recurring_next_date or fields.Date.context_today(self)
partner = self.contract_id.partner_id or self.env.user.partner_id
product = self.product_id.with_context(
lang=partner.lang,
partner=partner.id,
quantity=self.quantity,
date=date,
pricelist=self.contract_id.pricelist_id.id,
uom=self.uom_id.id,
)
vals["name"] = self.product_id.get_product_multiline_description_sale()
vals["price_unit"] = product.price
if self.product_id:
product = self.product_id.with_context(
lang=partner.lang,
partner=partner.id,
quantity=self.quantity,
date=date,
pricelist=self.contract_id.pricelist_id.id,
uom=self.uom_id.id,
)
vals["name"] = self.product_id.get_product_multiline_description_sale()
if self.contract_id.pricelist_id:
vals["price_unit"] = self.contract_id.pricelist_id._get_product_price(
product, quantity=1
)
else:
vals["price_unit"] = 0.0
self.update(vals)
13 changes: 8 additions & 5 deletions contract/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging

from odoo import api, fields, models
from odoo import Command, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.osv import expression
from odoo.tests import Form
Expand Down Expand Up @@ -312,7 +312,8 @@ def _compute_date_end(self):
@api.depends(
"contract_line_ids.recurring_next_date",
"contract_line_ids.is_canceled",
) # pylint: disable=missing-return
)
# pylint: disable=missing-return
def _compute_recurring_next_date(self):
for contract in self:
recurring_next_date = contract.contract_line_ids.filtered(
Expand Down Expand Up @@ -378,7 +379,7 @@ def _onchange_partner_id(self):
self.pricelist_id = partner.property_product_pricelist.id
self.fiscal_position_id = partner.env[
"account.fiscal.position"
].get_fiscal_position(partner.id)
]._get_fiscal_position(partner)
if self.contract_type == "purchase":
self.payment_term_id = partner.property_supplier_payment_term_id
else:
Expand Down Expand Up @@ -560,10 +561,12 @@ def _prepare_recurring_invoices_values(self, date_ref=False):
# nullifying line. We should then cleanup certain values.
del invoice_line_vals["company_id"]
del invoice_line_vals["company_currency_id"]
invoice_vals["invoice_line_ids"].append((0, 0, invoice_line_vals))
invoice_vals["invoice_line_ids"].append(
Command.create(invoice_line_vals)
)
invoices_values.append(invoice_vals)
# Force the recomputation of journal items
del invoice_vals["line_ids"]
# del invoice_vals["line_ids"] # TODO: Check why line_ids is missing here
contract_lines._update_recurring_next_date()
return invoices_values

Expand Down
23 changes: 8 additions & 15 deletions contract/models/contract_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class ContractLine(models.Model):
string="Analytic account",
comodel_name="account.analytic.account",
)
analytic_tag_ids = fields.Many2many(
comodel_name="account.analytic.tag",
string="Analytic Tags",
)
date_start = fields.Date(required=True)
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
termination_notice_date = fields.Date(
Expand Down Expand Up @@ -108,7 +104,8 @@ class ContractLine(models.Model):

@api.depends(
"last_date_invoiced", "date_start", "date_end", "contract_id.last_date_invoiced"
) # pylint: disable=missing-return
)
# pylint: disable=missing-return
def _compute_next_period_date_start(self):
"""Rectify next period date start if another line in the contract has been
already invoiced previously when the recurrence is by contract.
Expand Down Expand Up @@ -548,24 +545,22 @@ def _prepare_invoice_line(self, move_form):
self.last_date_invoiced, self.recurring_next_date
)
line_form = move_form.invoice_line_ids.new()
line_form.display_type = self.display_type
line_form.display_type = self.display_type or "product"
line_form.product_id = self.product_id
invoice_line_vals = line_form._values_to_save(all_fields=True)
name = self._insert_markers(dates[0], dates[1])
# TODO: We lost the analytic_account_id on invoice line vals
# - need to check what to use now
invoice_line_vals.update(
{
"account_id": invoice_line_vals["account_id"]
if "account_id" in invoice_line_vals and not self.display_type
else False,
"quantity": self._get_quantity_to_invoice(*dates),
"product_uom_id": self.uom_id.id,
"discount": self.discount,
"contract_line_id": self.id,
"sequence": self.sequence,
"name": name,
"analytic_account_id": self.analytic_account_id.id,
"analytic_tag_ids": [(6, 0, self.analytic_tag_ids.ids)],
"price_unit": self.price_unit,
"display_type": self.display_type or "product",
}
)
return invoice_line_vals
Expand Down Expand Up @@ -1071,9 +1066,7 @@ def cron_renew_contract_line(self):
to_renew.renew()

@api.model
def fields_view_get(
self, view_id=None, view_type="form", toolbar=False, submenu=False
):
def get_view(self, view_id=None, view_type="form", **options):
default_contract_type = self.env.context.get("default_contract_type")
if view_type == "tree" and default_contract_type == "purchase":
view_id = self.env.ref("contract.contract_line_supplier_tree_view").id
Expand All @@ -1082,7 +1075,7 @@ def fields_view_get(
view_id = self.env.ref("contract.contract_line_supplier_form_view").id
elif default_contract_type == "sale":
view_id = self.env.ref("contract.contract_line_customer_form_view").id
return super().fields_view_get(view_id, view_type, toolbar, submenu)
return super().get_view(view_id, view_type, **options)

def unlink(self):
"""stop unlink uncnacled lines"""
Expand Down
Loading

0 comments on commit 5a8fc96

Please sign in to comment.