Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] [MIG] product_contract #959

Merged
merged 148 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
7bbfbe1
[ADD] product_contract: Create module
Jan 12, 2017
a1aef2a
[FIX] product_contract: Fix mock usage in tests
lasley May 26, 2017
fc4cdef
[FIX] contract_sale_generation: it doesn't create sales (#141)
flotho Apr 1, 2018
1bb25a2
[MIG] - Product Contract Migration to 12.0
sbejaoui Oct 31, 2018
981fc8e
[IMP] - Product with is_contract can be only of type service
sbejaoui Oct 31, 2018
cf9131a
[IMP] - Change dependencies to contract_sale
sbejaoui Oct 31, 2018
8b52763
[IMP] - Add recurrence fields to product template and sale order line
sbejaoui Oct 31, 2018
dc2b4ae
[IMP] - Create contract on sale order confirmation
sbejaoui Nov 2, 2018
9d64e6f
[IMP] - Link contract line to sale order line
sbejaoui Nov 2, 2018
06ec626
[FIX] - Remove recurring_next_date from sale order line
sbejaoui Nov 2, 2018
5d626d6
[IMP] - Contract product are ignored on invoicing process
sbejaoui Nov 5, 2018
3679d75
[FIX] - Default value for date_start applied on product change
sbejaoui Nov 5, 2018
513d754
[ADD] - Add readme directory
sbejaoui Nov 5, 2018
6762d12
[IMP] - Onchange contract product on contract contract and contract t…
sbejaoui Nov 5, 2018
534f6a3
[FIX] - Change website to OCA repository url and prefix module name w…
sbejaoui Nov 5, 2018
1875a60
[FIX] - Compute recurring_next_date before create contract line
sbejaoui Nov 5, 2018
4db2c55
[IMP] - Upsell/Downsell contract from sale order
sbejaoui Nov 15, 2018
4ce0cb8
[ADD] - Add renewal process with termination notice
sbejaoui Nov 19, 2018
8abbd4a
[IMP] - compute date end onchange date start for auto-renew sale orde…
sbejaoui Nov 19, 2018
c218efb
[IMP] - link contract line and its successor in upsel case
sbejaoui Nov 26, 2018
1426baa
[FIX] - on upsel, contract line should stop day - 1
sbejaoui Nov 28, 2018
d081d7e
[FIX] - fix onchange
sbejaoui Nov 29, 2018
a5fc170
[IMP] - hide recurring_invoicing_type if recurring_rule_type is month…
sbejaoui Nov 29, 2018
758eac6
[FIX] - include date_end in the period if the product is_autorenew
sbejaoui Nov 30, 2018
07d104c
[IMP] - _prepare_contract_value for sale order confirm
sbejaoui Dec 3, 2018
5a0f24b
[REM] - Remove unused method
sbejaoui Dec 4, 2018
a5cd06b
[IMP] - get contract user from sale order user
sbejaoui Dec 13, 2018
41b6db3
[IMP] - show related sale orders in contract form
sbejaoui Dec 14, 2018
e7df781
[REF] Contract Product: invoice in prepare_invoice_line is optional
ThomasBinsfeld Dec 18, 2018
5f30846
[FIX] - fix flake8
sbejaoui Dec 20, 2018
cae46a4
[ADD] Product Contract: payment term
ThomasBinsfeld Dec 21, 2018
02f338a
[IMP] - update invoice_line vals only if it is not null
sbejaoui Dec 28, 2018
8bb36ab
[FIX] - fix unit tests
sbejaoui Jan 3, 2019
a42a1fb
[IMP] - Add unit test
sbejaoui Jan 10, 2019
2e06da2
[REF] - predecessor_contract_line set in create process
sbejaoui Jan 15, 2019
8ac0791
[IMP] - Simplify sale order line creation for contract product
sbejaoui Jan 21, 2019
57409be
[ADD] Contract Sale: fiscal position
ThomasBinsfeld Jan 23, 2019
23ddc31
[IMP] - auto_renew_rule deducted from recurring_rule_type and product…
sbejaoui Jan 24, 2019
e7a7bee
[FIX] Product Contract: copy invoicing partner to created contract
ThomasBinsfeld Jan 29, 2019
95cfc9d
[FIX] - Fix recurring_next_date
sbejaoui Jan 29, 2019
b5d0f54
[FIX] - date_end required only for contract product
sbejaoui Jan 29, 2019
b38a406
[FIX] - Get auto_renew_rule_type based on recurring_rule_type
sbejaoui Feb 1, 2019
e6b020c
[IMP] - cancel contract line if the downsell/upsell comes before
sbejaoui Feb 4, 2019
d1f5921
[FIX] - date_end computed only for contract products
sbejaoui Feb 6, 2019
74591f8
[REF] Contract: set order count to 0 if no access to orders
ThomasBinsfeld Feb 13, 2019
e6f1580
[IMP] - permit contract selection without contract_template_id
sbejaoui Feb 28, 2019
f9218d3
[ADD] Add start_date to contract_line display_name
qgroulard Sep 2, 2019
1795723
[12.0][IMP] - option to decide if we automaticallt create contract a …
sbejaoui Sep 5, 2019
b0920c3
[FIX] - fix display name compute dependecy
sbejaoui Sep 5, 2019
a2ac920
[12.0][FIX] - create contract only on sale and done states
sbejaoui Sep 11, 2019
b8fa244
[12.0][REF] - Split analytic accouts and contracts
sbejaoui Sep 17, 2019
1ea463d
[12.0][IMP] - Improve unit tests
sbejaoui Sep 30, 2019
5659a97
[IMP] - improve is contract visibility in product view
sbejaoui Sep 30, 2019
1b20b6e
[12.0][IMP] - sale line linked to contracts must not be invoiced from…
sbejaoui Oct 1, 2019
fc8271d
[UPD] README.rst
OCA-git-bot Oct 1, 2019
a9585bc
[ADD] icon.png
OCA-git-bot Oct 1, 2019
f5448f7
[FIX] - Remove deprecated field
sbejaoui Oct 1, 2019
827c655
[UPD] Update product_contract.pot
oca-travis Oct 1, 2019
81fa7ce
Update translation files
oca-transbot Oct 1, 2019
ef3431f
product_contract 12.0.2.0.1
OCA-git-bot Oct 2, 2019
a241c66
Translated using Weblate (German)
marylla Oct 9, 2019
ae4db4b
Translated using Weblate (Portuguese (Brazil))
britoederr Oct 10, 2019
9ae93d7
Translated using Weblate (German)
rschnapka Oct 29, 2019
1ce387b
[12.0][FIX] - contract company must be the same as the sale order
sbejaoui Oct 28, 2019
444c914
product_contract 12.0.2.0.2
OCA-git-bot Oct 30, 2019
69d97b8
[12.0][FIX] - Run onchange contract_type when changing the contract t…
sbejaoui Nov 26, 2019
fcc9731
Translated using Weblate (Croatian)
badbole Dec 2, 2019
ae9b8a0
Translated using Weblate (French)
Martronic-SA Dec 6, 2019
c3deba1
[IMP] contract: support pre-paid for monthlylastday
sbidoul Dec 8, 2019
48642c6
[IMP] - Set recurring_invoicing_type for existing products set to mon…
sbejaoui Dec 9, 2019
07ad88e
product_contract 12.0.3.0.0
OCA-git-bot Dec 12, 2019
cb57e3c
[12.0][FIX] - Set contract line analytic account at contract creation…
sbejaoui Dec 30, 2019
d6a91f1
[UPD] Update product_contract.pot
oca-travis Jan 7, 2020
4080435
product_contract 12.0.3.0.1
OCA-git-bot Jan 7, 2020
32b0292
Update translation files
oca-transbot Jan 7, 2020
4133b22
Translated using Weblate (Spanish)
Jan 17, 2020
b6452b3
product_contract 12.0.3.1.0
OCA-git-bot Jan 17, 2020
25982d0
[IMP] contract: remove redundant method
pedrobaeza Jan 8, 2020
f671acd
product_contract 12.0.3.1.1
OCA-git-bot Jan 30, 2020
ced533e
Translated using Weblate (Italian)
Feb 4, 2020
03bbd64
Translated using Weblate (Spanish)
Feb 4, 2020
5171a5e
[FIX]contract_count == len(active contracts)
Feb 5, 2020
9d345ba
Translated using Weblate (Portuguese (Brazil))
marcelsavegnago Feb 12, 2020
bdea2d3
Translated using Weblate (Portuguese)
pedrocs-exo Feb 17, 2020
c9f1870
Translated using Weblate (Portuguese)
pedrocs-exo Feb 17, 2020
5a77598
Translated using Weblate (Portuguese)
alvarorib Feb 18, 2020
879212b
[12.0][ADD] - add auto_renew_interval, auto_renew_rule_type fields to…
sbejaoui Feb 17, 2020
feb8054
[IMP] - Improve UX, open contract form if the sale order is related t…
sbejaoui Feb 25, 2020
fa5d032
product_contract 12.0.3.1.2
OCA-git-bot Mar 8, 2020
5071b11
[FIX] product_contract: set 'Contract template' field company depend
Feb 11, 2020
f70073d
[FIX] contract_sale_mandate: use property_contract_template_id
Feb 26, 2020
26ce84b
[UPD] Update product_contract.pot
oca-travis Mar 9, 2020
fe41c68
[UPD] README.rst
OCA-git-bot Mar 9, 2020
9d499a5
Update translation files
oca-transbot Mar 9, 2020
fc35919
[UPD] Update product_contract.pot
oca-travis Mar 9, 2020
f7b0c41
Update translation files
oca-transbot Mar 9, 2020
e5da204
[IMP] - can't upsell or downsell a resiliated contract
sbejaoui Jan 30, 2020
11ebcdc
[IMP] - use terminate term instead of resiliate
sbejaoui Mar 10, 2020
0930eb5
[UPD] Update product_contract.pot
oca-travis Mar 11, 2020
d5858ca
product_contract 12.0.5.0.0
OCA-git-bot Mar 11, 2020
7987c7e
Update translation files
oca-transbot Mar 11, 2020
fdb6b31
[UPD] Update product_contract.pot
oca-travis Mar 11, 2020
1e22bd3
Update translation files
oca-transbot Mar 11, 2020
ce2312f
[12.0][IMP] - Add failing test for creating contract grouped by contr…
sbejaoui Mar 17, 2020
9b2c420
[12.0][FIX] - fix contract creation group by contract template
sbejaoui Mar 17, 2020
63e62ff
Translated using Weblate (French)
svalaeys Mar 17, 2020
7e3c52f
[UPD] Update product_contract.pot
oca-travis Mar 17, 2020
a2bf238
product_contract 12.0.5.0.1
OCA-git-bot Mar 17, 2020
86e35b1
Update translation files
oca-transbot Mar 17, 2020
e27272f
[UPD] Update product_contract.pot
oca-travis Mar 17, 2020
88720ac
Update translation files
oca-transbot Mar 17, 2020
cd3e89b
product_contract 12.0.5.0.2
OCA-git-bot Mar 18, 2020
812792c
[FIX] migration from 11.0
sergiocorato Mar 24, 2020
3f0f8f6
Translated using Weblate (Spanish)
Mar 25, 2020
e63bd1f
[UPD] README.rst
OCA-git-bot Mar 25, 2020
15568ef
[UPD] README.rst
OCA-git-bot Mar 25, 2020
a1d4101
product_contract 12.0.5.0.3
OCA-git-bot Mar 30, 2020
69f4487
[UPD] Update product_contract.pot
oca-travis Apr 6, 2020
808c364
product_contract 12.0.5.0.4
OCA-git-bot Apr 6, 2020
403070c
Update translation files
oca-transbot Apr 6, 2020
c46f3b8
[UPD] Update product_contract.pot
oca-travis Apr 6, 2020
4e1ba9d
Update translation files
oca-transbot Apr 6, 2020
437ab0b
Translated using Weblate (Portuguese (Brazil))
eduaparicio May 13, 2020
98ea250
[IMP] - Contract: add new recurring_rule_type quarterly and semesterly
sbejaoui Apr 14, 2020
3c0a70f
[UPD] Update product_contract.pot
oca-travis May 18, 2020
420ccce
product_contract 12.0.5.1.0
OCA-git-bot May 18, 2020
267284f
Update translation files
oca-transbot May 18, 2020
ffd5b27
[UPD] Update product_contract.pot
oca-travis May 18, 2020
5ab24b2
Update translation files
oca-transbot May 18, 2020
1b45176
Translated using Weblate (Portuguese (Brazil))
fcolus Jun 16, 2020
392052b
Translated using Weblate (Spanish)
pedrobaeza Jun 17, 2020
6cec444
Translated using Weblate (Portuguese (Brazil))
fcolus Jun 17, 2020
aeb1725
Translated using Weblate (Portuguese (Brazil))
fcolus Aug 10, 2020
2a70157
Update translation files
oca-transbot Aug 16, 2020
b0ebf69
Translated using Weblate (French)
gregory-moka Aug 17, 2020
40c4c68
[13.0][MIG] - migration product_contract
sbejaoui Oct 24, 2020
fb5dc5e
[IMP] product_contract: black, isort, prettier
mourad-ehm Nov 12, 2021
0ff986a
[MIG] product_contract: Migration to 14.0
mourad-ehm Mar 9, 2021
4d312fb
[IMP] product_contract: use _compute_display_name. Moved it to contra…
ilyasProgrammer Mar 21, 2023
7856cf6
[IMP] product_contract: code improvements
ilyasProgrammer Mar 22, 2023
3d9ec4c
[UPD] Update product_contract.pot
Apr 12, 2023
d412c7e
[UPD] README.rst
OCA-git-bot Apr 12, 2023
467ae9b
product_contract 14.0.1.0.1
OCA-git-bot Apr 12, 2023
ca5b3fb
Translated using Weblate (Italian)
francesco-ooops Apr 13, 2023
ea504f1
Translated using Weblate (Italian)
mymage Apr 18, 2023
b5c4526
Translated using Weblate (Italian)
francesco-ooops Apr 18, 2023
b3f1fa3
[IMP] product_contract: pre-commit stuff
Rad0van Apr 29, 2023
a41cafe
[MIG] product_contract: Migration to 16.0
Rad0van Jun 8, 2023
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
23 changes: 13 additions & 10 deletions product_contract/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Recurring - Product Contract
============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ad8724fbb6c54e3f450ed7f3b3aa16384ed79b097065f0de96cc56e87eef2e71
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
Expand All @@ -14,16 +17,16 @@ Recurring - Product Contract
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github
:target: https://github.com/OCA/contract/tree/14.0/product_contract
:target: https://github.com/OCA/contract/tree/16.0/product_contract
:alt: OCA/contract
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/contract-14-0/contract-14-0-product_contract
:target: https://translation.odoo-community.org/projects/contract-16-0/contract-16-0-product_contract
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/110/14.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds support for products to be linked to contract templates.

Expand Down Expand Up @@ -51,8 +54,8 @@ Bug Tracker

Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/contract/issues/new?body=module:%20product_contract%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/contract/issues/new?body=module:%20product_contract%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -96,6 +99,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sbejaoui|

This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/14.0/product_contract>`_ project on GitHub.
This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/16.0/product_contract>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion product_contract/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Recurring - Product Contract",
"version": "14.0.1.0.1",
"version": "16.0.1.0.0",
"category": "Contract Management",
"license": "AGPL-3",
"author": "LasLabs, " "ACSONE SA/NV, " "Odoo Community Association (OCA)",
Expand Down
38 changes: 31 additions & 7 deletions product_contract/models/contract_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import api, fields, models
from odoo import Command, api, fields, models


class ContractLine(models.Model):
Expand All @@ -17,10 +17,10 @@ class ContractLine(models.Model):
copy=False,
)

def _prepare_invoice_line(self, move_form):
res = super(ContractLine, self)._prepare_invoice_line(move_form)
def _prepare_invoice_line(self):
res = super()._prepare_invoice_line()
if self.sale_order_line_id and res:
res["sale_line_ids"] = [(6, 0, [self.sale_order_line_id.id])]
res["sale_line_ids"] = [Command.set([self.sale_order_line_id.id])]
return res

def _get_auto_renew_rule_type(self):
Expand All @@ -37,9 +37,6 @@ def _onchange_product_id_recurring_info(self):
if rec.product_id.is_contract:
rec.update(
{
"recurring_rule_type": rec.product_id.recurring_rule_type,
"recurring_invoicing_type": rec.product_id.recurring_invoicing_type,
"recurring_interval": 1,
"is_auto_renew": rec.product_id.is_auto_renew,
"auto_renew_interval": rec.product_id.auto_renew_interval,
"auto_renew_rule_type": rec.product_id.auto_renew_rule_type,
Expand All @@ -51,3 +48,30 @@ def _onchange_product_id_recurring_info(self):
),
}
)

def _set_recurrence_field(self, field):
res = super()._set_recurrence_field(field)
for record in self:
if record.product_id.is_contract and field in record.product_id:
record[field] = record.product_id[field]
return res

@api.depends(
"contract_id.recurring_rule_type", "contract_id.line_recurrence", "product_id"
)
def _compute_recurring_rule_type(self):
return super()._compute_recurring_rule_type()

@api.depends(
"contract_id.recurring_invoicing_type",
"contract_id.line_recurrence",
"product_id",
)
def _compute_recurring_invoicing_type(self):
return super()._compute_recurring_invoicing_type()

@api.depends(
"contract_id.recurring_interval", "contract_id.line_recurrence", "product_id"
)
def _compute_recurring_interval(self):
return super()._compute_recurring_interval()
4 changes: 2 additions & 2 deletions product_contract/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ def write(self, vals):
self.with_company(company).write(
{"property_contract_template_id": False}
)
super().write(vals)
return super().write(vals)

@api.constrains("is_contract", "type")
def _check_contract_product_type(self):
"""
Contract product should be service type
"""
if self.is_contract and self.type != "service":
if any([product.is_contract and product.type != "service" for product in self]):
raise ValidationError(_("Contract product should be service type"))
21 changes: 12 additions & 9 deletions product_contract/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SaleOrder(models.Model):
need_contract_creation = fields.Boolean(compute="_compute_need_contract_creation")

@api.constrains("state")
def _check_contact_is_not_terminated(self):
def _check_contract_is_not_terminated(self):
for rec in self:
if rec.state not in (
"sale",
Expand Down Expand Up @@ -49,17 +49,15 @@ def _compute_is_contract(self):
def _prepare_contract_value(self, contract_template):
self.ensure_one()
return {
"name": "{template_name}: {sale_name}".format(
template_name=contract_template.name, sale_name=self.name
),
"name": f"{contract_template.name}: {self.name}",
"partner_id": self.partner_id.id,
"company_id": self.company_id.id,
"contract_template_id": contract_template.id,
"user_id": self.user_id.id,
"payment_term_id": self.payment_term_id.id,
"fiscal_position_id": self.fiscal_position_id.id,
"invoice_partner_id": self.partner_invoice_id.id,
"line_recurrence": self.partner_invoice_id.id,
"line_recurrence": True,
}

def action_create_contract(self):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I change the product_uom_qty before creating the contract, when creating the contract the quantity is doesn't match.

image
image

Expand All @@ -84,8 +82,13 @@ def action_create_contract(self):
raise ValidationError(
_(
"You must specify a contract "
"template for '{}' product in '{}' company."
).format(order_line.product_id.name, rec.company_id.name)
"template for '%(product_name)s' product "
"in '%(company_name)s' company."
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using translation method attributes.

_("You must specify (...) %(product_name)s (...)", product_name=(...), company_name=(...))

% {
"product_name": order_line.product_id.name,
"company_name": rec.company_id.name,
}
)
contract_templates |= contract_template
for contract_template in contract_templates:
Expand All @@ -98,7 +101,7 @@ def action_create_contract(self):
contract = contract_model.create(
rec._prepare_contract_value(contract_template)
)
contracts.append(contract)
contracts.append(contract.id)
contract._onchange_contract_template_id()
contract._onchange_contract_type()
order_lines.create_contract_line(contract)
Expand All @@ -112,7 +115,7 @@ def action_confirm(self):
self.filtered(
lambda order: (order.company_id.create_contract_at_sale_order_confirmation)
).action_create_contract()
return super(SaleOrder, self).action_confirm()
return super().action_confirm()

@api.depends("order_line")
def _compute_contract_count(self):
Expand Down
38 changes: 12 additions & 26 deletions product_contract/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class SaleOrderLine(models.Model):
help="Specify if process date is 'from' or 'to' invoicing date",
copy=False,
)
date_start = fields.Date(string="Date Start")
date_end = fields.Date(string="Date End")
date_start = fields.Date()
date_end = fields.Date()

contract_line_id = fields.Many2one(
comodel_name="contract.line",
Expand Down Expand Up @@ -93,7 +93,7 @@ def _check_contact_is_not_terminated(self):
_("You can't upsell or downsell a terminated contract")
)

@api.depends("product_id")
@api.depends("product_id", "order_id.company_id")
def _compute_contract_template_id(self):
for rec in self:
rec.contract_template_id = rec.product_id.with_company(
Expand Down Expand Up @@ -141,21 +141,13 @@ def onchange_date_start(self):
rec.date_end = rec._get_date_end() if rec.date_start else False

def _get_contract_line_qty(self):
"""Returns the quantity to be put on new contract lines."""
"""Returns the amount that will be placed in new contract lines."""
self.ensure_one()
# The quantity on the generated contract line is 1, as it
# correspond to the most common use cases:
# - quantity on the SO line = number of periods sold and unit
# price the price of one period, so the
# total amount of the SO corresponds to the planned value
# of the contract; in this case the quantity on the contract
# line must be 1
# - quantity on the SO line = number of hours sold,
# automatic invoicing of the actual hours through a variable
# quantity formula, in which case the quantity on the contract
# line is not used
# The quantity in the generated contract line is the quantity of
# product requested in the order, since they correspond to the most common
# use cases.
# Other use cases are easy to implement by overriding this method.
return 1.0
return self.product_uom_qty

def _prepare_contract_line_values(
self, contract, predecessor_contract_line_id=False
Expand Down Expand Up @@ -198,7 +190,7 @@ def _prepare_contract_line_values(
"contract_id": contract.id,
"sale_order_line_id": self.id,
"predecessor_contract_line_id": predecessor_contract_line_id,
"analytic_account_id": self.order_id.analytic_account_id.id,
"analytic_distribution": self.analytic_distribution,
}

def create_contract_line(self, contract):
Expand Down Expand Up @@ -269,17 +261,11 @@ def invoice_line_create(self, invoice_id, qty):
SaleOrderLine, self.filtered(lambda l: not l.contract_id)
).invoice_line_create(invoice_id, qty)

@api.depends(
"qty_invoiced",
"qty_delivered",
"product_uom_qty",
"order_id.state",
"product_id.is_contract",
)
def _get_to_invoice_qty(self):
@api.depends("qty_invoiced", "qty_delivered", "product_uom_qty", "state")
def _compute_qty_to_invoice(self):
"""
sale line linked to contracts must not be invoiced from sale order
"""
res = super()._get_to_invoice_qty()
res = super()._compute_qty_to_invoice()
self.filtered("product_id.is_contract").update({"qty_to_invoice": 0.0})
return res
Loading
Loading