mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] contract_sale_invoicing: pre-commit stuff
This commit is contained in:
@@ -2,4 +2,3 @@
|
|||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
from . import tests
|
from . import tests
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
# Copyright 2018 Tecnativa - Carlos Dauden
|
# Copyright 2018 Tecnativa - Carlos Dauden
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
{
|
{
|
||||||
'name': 'Contract Invoicing of Pending Sales Orders',
|
"name": "Contract Invoicing of Pending Sales Orders",
|
||||||
'summary': 'Include sales to invoice in contract invoice creation',
|
"summary": "Include sales to invoice in contract invoice creation",
|
||||||
'version': '12.0.1.0.4',
|
"version": "12.0.1.0.4",
|
||||||
'category': 'Contract Management',
|
"category": "Contract Management",
|
||||||
'website': 'https://github.com/OCA/contract',
|
"website": "https://github.com/OCA/contract",
|
||||||
'author': 'Tecnativa, '
|
"author": "Tecnativa, " "Odoo Community Association (OCA)",
|
||||||
'Odoo Community Association (OCA)',
|
"license": "AGPL-3",
|
||||||
'license': 'AGPL-3',
|
"installable": True,
|
||||||
'installable': True,
|
"depends": [
|
||||||
'depends': [
|
"contract",
|
||||||
'contract',
|
"sale_management",
|
||||||
'sale_management',
|
|
||||||
],
|
],
|
||||||
'data': [
|
"data": [
|
||||||
'views/contract_view.xml',
|
"views/contract_view.xml",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ from odoo import api, fields, models
|
|||||||
|
|
||||||
|
|
||||||
class ContractContract(models.Model):
|
class ContractContract(models.Model):
|
||||||
_inherit = 'contract.contract'
|
_inherit = "contract.contract"
|
||||||
|
|
||||||
invoicing_sales = fields.Boolean(
|
invoicing_sales = fields.Boolean(
|
||||||
string='Invoice Pending Sales Orders',
|
string="Invoice Pending Sales Orders",
|
||||||
help='If checked include sales with same analytic account to invoice '
|
help="If checked include sales with same analytic account to invoice "
|
||||||
'in contract invoice creation.',
|
"in contract invoice creation.",
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -19,16 +19,24 @@ class ContractContract(models.Model):
|
|||||||
for contract in self:
|
for contract in self:
|
||||||
if not contract.invoicing_sales or not contract.recurring_next_date:
|
if not contract.invoicing_sales or not contract.recurring_next_date:
|
||||||
continue
|
continue
|
||||||
sales = self.env['sale.order'].search([
|
sales = self.env["sale.order"].search(
|
||||||
('analytic_account_id', '=', contract.group_id.id),
|
[
|
||||||
('partner_invoice_id', 'child_of',
|
("analytic_account_id", "=", contract.group_id.id),
|
||||||
contract.partner_id.commercial_partner_id.ids),
|
(
|
||||||
('invoice_status', '=', 'to invoice'),
|
"partner_invoice_id",
|
||||||
('date_order', '<=',
|
"child_of",
|
||||||
'{} 23:59:59'.format(contract.recurring_next_date)),
|
contract.partner_id.commercial_partner_id.ids,
|
||||||
])
|
),
|
||||||
|
("invoice_status", "=", "to invoice"),
|
||||||
|
(
|
||||||
|
"date_order",
|
||||||
|
"<=",
|
||||||
|
"{} 23:59:59".format(contract.recurring_next_date),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
if sales:
|
if sales:
|
||||||
invoice_ids = sales.action_invoice_create()
|
invoice_ids = sales.action_invoice_create()
|
||||||
invoices |= self.env['account.invoice'].browse(invoice_ids)[:1]
|
invoices |= self.env["account.invoice"].browse(invoice_ids)[:1]
|
||||||
|
|
||||||
return invoices
|
return invoices
|
||||||
|
|||||||
@@ -8,40 +8,48 @@ class TestContractSaleInvoicing(TestContractBase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(TestContractSaleInvoicing, cls).setUpClass()
|
super(TestContractSaleInvoicing, cls).setUpClass()
|
||||||
cls.contract.group_id = \
|
cls.contract.group_id = cls.env["account.analytic.account"].search([], limit=1)
|
||||||
cls.env['account.analytic.account'].search([], limit=1)
|
cls.product_so = cls.env.ref("product.product_product_1")
|
||||||
cls.product_so = cls.env.ref(
|
cls.product_so.invoice_policy = "order"
|
||||||
'product.product_product_1')
|
cls.sale_order = cls.env["sale.order"].create(
|
||||||
cls.product_so.invoice_policy = 'order'
|
{
|
||||||
cls.sale_order = cls.env['sale.order'].create({
|
"partner_id": cls.partner.id,
|
||||||
'partner_id': cls.partner.id,
|
"partner_invoice_id": cls.partner.id,
|
||||||
'partner_invoice_id': cls.partner.id,
|
"partner_shipping_id": cls.partner.id,
|
||||||
'partner_shipping_id': cls.partner.id,
|
"order_line": [
|
||||||
'order_line': [(0, 0, {'name': cls.product_so.name,
|
(
|
||||||
'product_id': cls.product_so.id,
|
0,
|
||||||
'product_uom_qty': 2,
|
0,
|
||||||
'product_uom': cls.product_so.uom_id.id,
|
{
|
||||||
'price_unit': cls.product_so.list_price})],
|
"name": cls.product_so.name,
|
||||||
'pricelist_id': cls.partner.property_product_pricelist.id,
|
"product_id": cls.product_so.id,
|
||||||
'analytic_account_id': cls.contract.group_id.id,
|
"product_uom_qty": 2,
|
||||||
'date_order': '2016-02-15',
|
"product_uom": cls.product_so.uom_id.id,
|
||||||
})
|
"price_unit": cls.product_so.list_price,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
"pricelist_id": cls.partner.property_product_pricelist.id,
|
||||||
|
"analytic_account_id": cls.contract.group_id.id,
|
||||||
|
"date_order": "2016-02-15",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def test_not_sale_invoicing(self):
|
def test_not_sale_invoicing(self):
|
||||||
self.contract.invoicing_sales = False
|
self.contract.invoicing_sales = False
|
||||||
self.sale_order.action_confirm()
|
self.sale_order.action_confirm()
|
||||||
self.contract.recurring_create_invoice()
|
self.contract.recurring_create_invoice()
|
||||||
self.assertEqual(self.sale_order.invoice_status, 'to invoice')
|
self.assertEqual(self.sale_order.invoice_status, "to invoice")
|
||||||
|
|
||||||
def test_sale_invoicing(self):
|
def test_sale_invoicing(self):
|
||||||
self.contract.invoicing_sales = True
|
self.contract.invoicing_sales = True
|
||||||
self.sale_order.action_confirm()
|
self.sale_order.action_confirm()
|
||||||
self.contract.recurring_create_invoice()
|
self.contract.recurring_create_invoice()
|
||||||
self.assertEqual(self.sale_order.invoice_status, 'invoiced')
|
self.assertEqual(self.sale_order.invoice_status, "invoiced")
|
||||||
|
|
||||||
def test_contract_sale_invoicing_without(self):
|
def test_contract_sale_invoicing_without(self):
|
||||||
self.contract.invoicing_sales = True
|
self.contract.invoicing_sales = True
|
||||||
self.sale_order.analytic_account_id = False
|
self.sale_order.analytic_account_id = False
|
||||||
self.sale_order.action_confirm()
|
self.sale_order.action_confirm()
|
||||||
self.contract.recurring_create_invoice()
|
self.contract.recurring_create_invoice()
|
||||||
self.assertEqual(self.sale_order.invoice_status, 'to invoice')
|
self.assertEqual(self.sale_order.invoice_status, "to invoice")
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<!-- Copyright 2018 Tecnativa - Carlos Dauden
|
<!-- Copyright 2018 Tecnativa - Carlos Dauden
|
||||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||||
|
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<record id="contract_contract_form_view" model="ir.ui.view">
|
<record id="contract_contract_form_view" model="ir.ui.view">
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../contract_sale_invoicing
|
||||||
6
setup/contract_sale_invoicing/setup.py
Normal file
6
setup/contract_sale_invoicing/setup.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user