[MIG] contract_sale_generation: Migration to 15.0

This commit is contained in:
ntsirintanis
2022-06-22 11:54:53 +02:00
committed by Jesús Feliciano Valdez Cruz [Vauxoo]
parent 42b907c7d2
commit 0730d45f09
10 changed files with 67 additions and 55 deletions

View File

@@ -14,13 +14,13 @@ Contracts Management - Recurring Sales
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github
:target: https://github.com/OCA/contract/tree/14.0/contract_sale_generation :target: https://github.com/OCA/contract/tree/15.0/contract_sale_generation
:alt: OCA/contract :alt: OCA/contract
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |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-contract_sale_generation :target: https://translation.odoo-community.org/projects/contract-15-0/contract-15-0-contract_sale_generation
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/110/14.0 :target: https://runbot.odoo-community.org/runbot/110/15.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@@ -50,7 +50,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/issues>`_. 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. 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 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:%20contract_sale_generation%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/contract/issues/new?body=module:%20contract_sale_generation%0Aversion:%2015.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. Do not contact contributors directly about support or help with technical issues.
@@ -84,6 +84,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/14.0/contract_sale_generation>`_ project on GitHub. This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/15.0/contract_sale_generation>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -5,7 +5,7 @@
{ {
"name": "Contracts Management - Recurring Sales", "name": "Contracts Management - Recurring Sales",
"version": "14.0.1.0.1", "version": "15.0.1.0.2",
"category": "Contract Management", "category": "Contract Management",
"license": "AGPL-3", "license": "AGPL-3",
"author": "ACSONE SA/NV, PESOL, Odoo Community Association (OCA)", "author": "ACSONE SA/NV, PESOL, Odoo Community Association (OCA)",

View File

@@ -4,7 +4,7 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 14.0\n" "Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
@@ -43,17 +43,8 @@ msgstr ""
#: code:addons/contract_sale_generation/models/contract.py:0 #: code:addons/contract_sale_generation/models/contract.py:0
#, python-format #, python-format
msgid "" msgid ""
"Contract manually sale order: <a href=\"#\" data-oe-model=\"%s\" data-oe-" "Contract manually sale order: <a href=\"#\" data-oe-model=\"%(model)s\" "
"id=\"%s\">Sale Order</a>" "data-oe-id=\"%(id)s\">Sale Order</a>"
msgstr ""
#. module: contract_sale_generation
#: model:ir.model.fields,field_description:contract_sale_generation.field_contract_abstract_contract__display_name
#: model:ir.model.fields,field_description:contract_sale_generation.field_contract_contract__display_name
#: model:ir.model.fields,field_description:contract_sale_generation.field_contract_line__display_name
#: model:ir.model.fields,field_description:contract_sale_generation.field_sale_order__display_name
#: model:ir.model.fields,field_description:contract_sale_generation.field_sale_order_line__display_name
msgid "Display Name"
msgstr "" msgstr ""
#. module: contract_sale_generation #. module: contract_sale_generation
@@ -63,24 +54,6 @@ msgstr ""
msgid "Generate Recurring sales from Contracts" msgid "Generate Recurring sales from Contracts"
msgstr "" msgstr ""
#. module: contract_sale_generation
#: model:ir.model.fields,field_description:contract_sale_generation.field_contract_abstract_contract__id
#: model:ir.model.fields,field_description:contract_sale_generation.field_contract_contract__id
#: model:ir.model.fields,field_description:contract_sale_generation.field_contract_line__id
#: model:ir.model.fields,field_description:contract_sale_generation.field_sale_order__id
#: model:ir.model.fields,field_description:contract_sale_generation.field_sale_order_line__id
msgid "ID"
msgstr ""
#. module: contract_sale_generation
#: model:ir.model.fields,field_description:contract_sale_generation.field_contract_abstract_contract____last_update
#: model:ir.model.fields,field_description:contract_sale_generation.field_contract_contract____last_update
#: model:ir.model.fields,field_description:contract_sale_generation.field_contract_line____last_update
#: model:ir.model.fields,field_description:contract_sale_generation.field_sale_order____last_update
#: model:ir.model.fields,field_description:contract_sale_generation.field_sale_order_line____last_update
msgid "Last Modified on"
msgstr ""
#. module: contract_sale_generation #. module: contract_sale_generation
#: model:ir.model.fields,field_description:contract_sale_generation.field_contract_abstract_contract__sale_autoconfirm #: model:ir.model.fields,field_description:contract_sale_generation.field_contract_abstract_contract__sale_autoconfirm
#: model:ir.model.fields,field_description:contract_sale_generation.field_contract_contract__sale_autoconfirm #: model:ir.model.fields,field_description:contract_sale_generation.field_contract_contract__sale_autoconfirm

View File

@@ -8,7 +8,7 @@ from odoo import api, fields, models
class ContractAbstractContract(models.AbstractModel): class ContractAbstractContract(models.AbstractModel):
_inherit = "contract.abstract.contract" _inherit = "contract.abstract.contract"
sale_autoconfirm = fields.Boolean(string="Sale Autoconfirm") sale_autoconfirm = fields.Boolean()
@api.model @api.model
def _selection_generation_type(self): def _selection_generation_type(self):

View File

@@ -75,11 +75,11 @@ class ContractContract(models.Model):
self.message_post( self.message_post(
body=_( body=_(
"Contract manually sale order: " "Contract manually sale order: "
'<a href="#" data-oe-model="%s" data-oe-id="%s">' '<a href="#" data-oe-model="%(model)s" data-oe-id="%(id)s">'
"Sale Order" "Sale Order"
"</a>" "</a>"
) )
% (sale_rec._name, sale_rec.id) % {"model": sale_rec._name, "id": sale_rec.id}
) )
return sales return sales

View File

@@ -25,7 +25,7 @@ class ContractLine(models.Model):
dates = self._get_period_to_invoice( dates = self._get_period_to_invoice(
self.last_date_invoiced, self.recurring_next_date self.last_date_invoiced, self.recurring_next_date
) )
sale_line_vals = self._prepare_sale_line_vals(dates, order_id) sale_line_vals = self._prepare_sale_line_vals(dates, order_id=order_id)
order_line = ( order_line = (
self.env["sale.order.line"] self.env["sale.order.line"]

View File

@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" 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" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/contract/tree/14.0/contract_sale_generation"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/contract-14-0/contract-14-0-contract_sale_generation"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/110/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" 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" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/contract/tree/15.0/contract_sale_generation"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/contract-15-0/contract-15-0-contract_sale_generation"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/110/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module extends functionality of contracts to be able to generate sales <p>This module extends functionality of contracts to be able to generate sales
orders instead of invoices.</p> orders instead of invoices.</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
@@ -400,7 +400,7 @@ orders instead of invoices.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/contract/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/contract/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/contract/issues/new?body=module:%20contract_sale_generation%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/contract/issues/new?body=module:%20contract_sale_generation%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@@ -428,7 +428,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/contract/tree/14.0/contract_sale_generation">OCA/contract</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/contract/tree/15.0/contract_sale_generation">OCA/contract</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@@ -24,6 +24,12 @@ class ContractSaleCommon:
"name": "Contracts", "name": "Contracts",
} }
) )
cls.payment_term_id = cls.env.ref(
"account.account_payment_term_end_following_month"
)
cls.fiscal_position_id = cls.env["account.fiscal.position"].create(
{"name": "Contracts"}
)
contract_date = "2020-01-15" contract_date = "2020-01-15"
cls.pricelist = cls.env["product.pricelist"].create( cls.pricelist = cls.env["product.pricelist"].create(
{ {
@@ -34,6 +40,8 @@ class ContractSaleCommon:
{ {
"name": "partner test contract", "name": "partner test contract",
"property_product_pricelist": cls.pricelist.id, "property_product_pricelist": cls.pricelist.id,
"property_payment_term_id": cls.payment_term_id.id,
"property_account_position_id": cls.fiscal_position_id.id,
} }
) )
cls.product_1 = cls.env.ref("product.product_product_1") cls.product_1 = cls.env.ref("product.product_product_1")

View File

@@ -3,15 +3,10 @@
# Copyright 2017 Angel Moya <angel.moya@pesol.es> # Copyright 2017 Angel Moya <angel.moya@pesol.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.tests.common import SavepointCase from odoo.tests.common import SavepointCase
from .common import ContractSaleCommon from .common import ContractSaleCommon, to_date
def to_date(date):
return fields.Date.to_date(date)
class TestContractSale(ContractSaleCommon, SavepointCase): class TestContractSale(ContractSaleCommon, SavepointCase):
@@ -96,6 +91,11 @@ class TestContractSale(ContractSaleCommon, SavepointCase):
self.contract_line.recurring_invoicing_type = "post-paid" self.contract_line.recurring_invoicing_type = "post-paid"
self.contract_line.date_end = "2020-03-15" self.contract_line.date_end = "2020-03-15"
self.contract_line._onchange_is_auto_renew() self.contract_line._onchange_is_auto_renew()
# If we do not recompute recurring_next_date
# then it maintains it's 'old' value.
# TODO: Research that
recurring_next_date = self.contract_line.recurring_next_date
self.assertGreaterEqual(recurring_next_date, self.contract_line.date_start)
contracts = self.contract2 contracts = self.contract2
for _i in range(10): for _i in range(10):
contracts |= self.contract.copy({"generation_type": "sale"}) contracts |= self.contract.copy({"generation_type": "sale"})
@@ -108,7 +108,43 @@ class TestContractSale(ContractSaleCommon, SavepointCase):
len(order_lines), len(order_lines),
) )
def test_contract_sale_analytic(self): def test_contract_sale_analytic_payment_term_fiscal_position(self):
# Call onchange in order to retrieve
# payment term and fiscal position
self.contract._onchange_partner_id()
orders = self.env["sale.order"].browse() orders = self.env["sale.order"].browse()
orders |= self.contract.recurring_create_sale() orders |= self.contract.recurring_create_sale()
self.assertEqual(self.analytic_account, orders.mapped("analytic_account_id")) self.assertEqual(self.analytic_account, orders.mapped("analytic_account_id"))
self.assertEqual(self.payment_term_id, orders.mapped("payment_term_id"))
self.assertEqual(self.fiscal_position_id, orders.mapped("fiscal_position_id"))
def test_recurring_method_retrieval(self):
self.assertNotEqual(
self.contract._get_recurring_create_func(create_type="sale"),
self.contract._get_recurring_create_func(create_type="invoice"),
)
def test__prepare_recurring_sales_values_no_date_ref(self):
self.contract.recurring_next_date = False
self.assertEqual(self.contract._prepare_recurring_sales_values(), [])
def test__prepare_recurring_sales_values_no_contract_lines(self):
a_contract_with_no_lines = self.env["contract.contract"].create(
{
"name": "No lines Contract",
"partner_id": self.partner.id,
"generation_type": "sale",
"date_start": "2020-01-15",
}
)
self.assertEqual(a_contract_with_no_lines._prepare_recurring_sales_values(), [])
def test__prepare_sale_line_vals_with_order_id(self):
order = self.contract.recurring_create_sale()[0]
recurring_next_date = self.contract.recurring_next_date
date_start = self.contract.date_start
date_end = self.contract.date_end
dates = [date_start, date_end, recurring_next_date]
for line in self.contract._get_lines_to_invoice(recurring_next_date):
line_vals = line._prepare_sale_line_vals(dates, order)
self.assertEqual(line_vals["order_id"], order.id)

View File

@@ -9,11 +9,6 @@ from odoo.tests.common import SavepointCase
from .common import ContractSaleCommon from .common import ContractSaleCommon
def to_date(date):
return fields.Date.to_date(date)
today = "2020-01-15" today = "2020-01-15"