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 tests
|
||||
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
# Copyright 2018 Tecnativa - Carlos Dauden
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
{
|
||||
'name': 'Contract Invoicing of Pending Sales Orders',
|
||||
'summary': 'Include sales to invoice in contract invoice creation',
|
||||
'version': '12.0.1.0.4',
|
||||
'category': 'Contract Management',
|
||||
'website': 'https://github.com/OCA/contract',
|
||||
'author': 'Tecnativa, '
|
||||
'Odoo Community Association (OCA)',
|
||||
'license': 'AGPL-3',
|
||||
'installable': True,
|
||||
'depends': [
|
||||
'contract',
|
||||
'sale_management',
|
||||
"name": "Contract Invoicing of Pending Sales Orders",
|
||||
"summary": "Include sales to invoice in contract invoice creation",
|
||||
"version": "12.0.1.0.4",
|
||||
"category": "Contract Management",
|
||||
"website": "https://github.com/OCA/contract",
|
||||
"author": "Tecnativa, " "Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
"installable": True,
|
||||
"depends": [
|
||||
"contract",
|
||||
"sale_management",
|
||||
],
|
||||
'data': [
|
||||
'views/contract_view.xml',
|
||||
"data": [
|
||||
"views/contract_view.xml",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ from odoo import api, fields, models
|
||||
|
||||
|
||||
class ContractContract(models.Model):
|
||||
_inherit = 'contract.contract'
|
||||
_inherit = "contract.contract"
|
||||
|
||||
invoicing_sales = fields.Boolean(
|
||||
string='Invoice Pending Sales Orders',
|
||||
help='If checked include sales with same analytic account to invoice '
|
||||
'in contract invoice creation.',
|
||||
string="Invoice Pending Sales Orders",
|
||||
help="If checked include sales with same analytic account to invoice "
|
||||
"in contract invoice creation.",
|
||||
)
|
||||
|
||||
@api.multi
|
||||
@@ -19,16 +19,24 @@ class ContractContract(models.Model):
|
||||
for contract in self:
|
||||
if not contract.invoicing_sales or not contract.recurring_next_date:
|
||||
continue
|
||||
sales = self.env['sale.order'].search([
|
||||
('analytic_account_id', '=', contract.group_id.id),
|
||||
('partner_invoice_id', 'child_of',
|
||||
contract.partner_id.commercial_partner_id.ids),
|
||||
('invoice_status', '=', 'to invoice'),
|
||||
('date_order', '<=',
|
||||
'{} 23:59:59'.format(contract.recurring_next_date)),
|
||||
])
|
||||
sales = self.env["sale.order"].search(
|
||||
[
|
||||
("analytic_account_id", "=", contract.group_id.id),
|
||||
(
|
||||
"partner_invoice_id",
|
||||
"child_of",
|
||||
contract.partner_id.commercial_partner_id.ids,
|
||||
),
|
||||
("invoice_status", "=", "to invoice"),
|
||||
(
|
||||
"date_order",
|
||||
"<=",
|
||||
"{} 23:59:59".format(contract.recurring_next_date),
|
||||
),
|
||||
]
|
||||
)
|
||||
if sales:
|
||||
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
|
||||
|
||||
@@ -8,40 +8,48 @@ class TestContractSaleInvoicing(TestContractBase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestContractSaleInvoicing, cls).setUpClass()
|
||||
cls.contract.group_id = \
|
||||
cls.env['account.analytic.account'].search([], limit=1)
|
||||
cls.product_so = cls.env.ref(
|
||||
'product.product_product_1')
|
||||
cls.product_so.invoice_policy = 'order'
|
||||
cls.sale_order = cls.env['sale.order'].create({
|
||||
'partner_id': cls.partner.id,
|
||||
'partner_invoice_id': cls.partner.id,
|
||||
'partner_shipping_id': cls.partner.id,
|
||||
'order_line': [(0, 0, {'name': cls.product_so.name,
|
||||
'product_id': cls.product_so.id,
|
||||
'product_uom_qty': 2,
|
||||
'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',
|
||||
})
|
||||
cls.contract.group_id = cls.env["account.analytic.account"].search([], limit=1)
|
||||
cls.product_so = cls.env.ref("product.product_product_1")
|
||||
cls.product_so.invoice_policy = "order"
|
||||
cls.sale_order = cls.env["sale.order"].create(
|
||||
{
|
||||
"partner_id": cls.partner.id,
|
||||
"partner_invoice_id": cls.partner.id,
|
||||
"partner_shipping_id": cls.partner.id,
|
||||
"order_line": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": cls.product_so.name,
|
||||
"product_id": cls.product_so.id,
|
||||
"product_uom_qty": 2,
|
||||
"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):
|
||||
self.contract.invoicing_sales = False
|
||||
self.sale_order.action_confirm()
|
||||
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):
|
||||
self.contract.invoicing_sales = True
|
||||
self.sale_order.action_confirm()
|
||||
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):
|
||||
self.contract.invoicing_sales = True
|
||||
self.sale_order.analytic_account_id = False
|
||||
self.sale_order.action_confirm()
|
||||
self.contract.recurring_create_invoice()
|
||||
self.assertEqual(self.sale_order.invoice_status, 'to invoice')
|
||||
self.assertEqual(self.sale_order.invoice_status, "to invoice")
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2018 Tecnativa - Carlos Dauden
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="contract_contract_form_view" model="ir.ui.view">
|
||||
<field name="model">contract.contract</field>
|
||||
<field name="inherit_id" ref="contract.contract_contract_form_view"/>
|
||||
<field name="inherit_id" ref="contract.contract_contract_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="recurring_next_date" position="after">
|
||||
<field name="invoicing_sales"/>
|
||||
<field name="invoicing_sales" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -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