mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[MIG] contract_sale_generation: Migration to 15.0
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
{
|
||||
"name": "Contracts Management - Recurring Sales",
|
||||
"version": "14.0.1.0.1",
|
||||
"version": "15.0.1.0.1",
|
||||
"category": "Contract Management",
|
||||
"license": "AGPL-3",
|
||||
"author": "ACSONE SA/NV, PESOL, Odoo Community Association (OCA)",
|
||||
|
||||
@@ -8,7 +8,7 @@ from odoo import api, fields, models
|
||||
class ContractAbstractContract(models.AbstractModel):
|
||||
_inherit = "contract.abstract.contract"
|
||||
|
||||
sale_autoconfirm = fields.Boolean(string="Sale Autoconfirm")
|
||||
sale_autoconfirm = fields.Boolean()
|
||||
|
||||
@api.model
|
||||
def _selection_generation_type(self):
|
||||
|
||||
@@ -75,11 +75,11 @@ class ContractContract(models.Model):
|
||||
self.message_post(
|
||||
body=_(
|
||||
"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"
|
||||
"</a>"
|
||||
)
|
||||
% (sale_rec._name, sale_rec.id)
|
||||
% {"model": sale_rec._name, "id": sale_rec.id}
|
||||
)
|
||||
return sales
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class ContractLine(models.Model):
|
||||
dates = self._get_period_to_invoice(
|
||||
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 = (
|
||||
self.env["sale.order.line"]
|
||||
|
||||
@@ -24,6 +24,12 @@ class ContractSaleCommon:
|
||||
"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"
|
||||
cls.pricelist = cls.env["product.pricelist"].create(
|
||||
{
|
||||
@@ -34,6 +40,8 @@ class ContractSaleCommon:
|
||||
{
|
||||
"name": "partner test contract",
|
||||
"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")
|
||||
|
||||
@@ -3,15 +3,10 @@
|
||||
# Copyright 2017 Angel Moya <angel.moya@pesol.es>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests.common import SavepointCase
|
||||
|
||||
from .common import ContractSaleCommon
|
||||
|
||||
|
||||
def to_date(date):
|
||||
return fields.Date.to_date(date)
|
||||
from .common import ContractSaleCommon, to_date
|
||||
|
||||
|
||||
class TestContractSale(ContractSaleCommon, SavepointCase):
|
||||
@@ -96,6 +91,11 @@ class TestContractSale(ContractSaleCommon, SavepointCase):
|
||||
self.contract_line.recurring_invoicing_type = "post-paid"
|
||||
self.contract_line.date_end = "2020-03-15"
|
||||
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
|
||||
for _i in range(10):
|
||||
contracts |= self.contract.copy({"generation_type": "sale"})
|
||||
@@ -108,7 +108,43 @@ class TestContractSale(ContractSaleCommon, SavepointCase):
|
||||
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.contract.recurring_create_sale()
|
||||
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)
|
||||
|
||||
@@ -9,11 +9,6 @@ from odoo.tests.common import SavepointCase
|
||||
|
||||
from .common import ContractSaleCommon
|
||||
|
||||
|
||||
def to_date(date):
|
||||
return fields.Date.to_date(date)
|
||||
|
||||
|
||||
today = "2020-01-15"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user