Browse Source

Merge pull request #2 from ursais/12.0-imp-contract_sale_invoicing

[IMP] contract_sale_invoicing
pull/437/head
Nikul Chaudhary 5 years ago
committed by GitHub
parent
commit
32a41ce72b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 63
      contract_sale_invoicing/models/contract.py
  2. 2
      contract_sale_invoicing/views/contract_view.xml

63
contract_sale_invoicing/models/contract.py

@ -9,15 +9,31 @@ class ContractContract(models.Model):
invoicing_sales = fields.Boolean(
string='Invoice Pending Sales Orders',
help='If checked include sales with same analytic account to invoice '
'in contract invoice creation.',
)
group_by = fields.Selection(
[('analytic_account', 'Analytic Account'),
('contract', 'Contract')],
default='analytic_account',
string='Group By'
)
help='Include sales to invoice on the contract invoice.')
filter_with = fields.Selection([
('analytic_account', 'Analytic Account'),
('contract', 'Contract')],
default='analytic_account', string='Filter with the same',
help="Select the sale orders with the same analytic account or "
"contract")
group_by = fields.Selection([
('sale_order', 'Sale Order'),
('contract', 'Contract')],
default='sale_order', string='Create one invoice per')
def get_sale_order_domain(self):
domain = [
('partner_invoice_id', 'child_of',
self.partner_id.commercial_partner_id.ids),
('invoice_status', '=', 'to invoice'),
('date_order', '<=',
'{} 23:59:59'.format(self.recurring_next_date)),
]
if self.filter_with == 'analytic_account':
domain.append(('analytic_account_id', '=', self.group_id.id))
elif self.filter_with == 'contract':
domain.append(('contract_id', '=', self.id))
return domain
@api.multi
def _recurring_create_invoice(self, date_ref=False):
@ -25,15 +41,9 @@ class ContractContract(models.Model):
for rec in self:
if not rec.invoicing_sales:
return invoices
sales = self.env['sale.order'].search([
('analytic_account_id', '=', rec.group_id.id),
('partner_invoice_id', 'child_of',
rec.partner_id.commercial_partner_id.ids),
('invoice_status', '=', 'to invoice'),
('date_order', '<=',
'{} 23:59:59'.format(rec.recurring_next_date)),
])
if sales:
so_domain = rec.get_sale_order_domain()
sales = self.env['sale.order'].search(so_domain)
if sales and self.group_by == 'sale_order':
invoice_ids = sales.action_invoice_create()
invoices |= self.env['account.invoice'].browse(invoice_ids)[:1]
@ -54,8 +64,7 @@ class ContractContract(models.Model):
@api.multi
def _prepare_recurring_invoices_values(self, date_ref=False):
invoices_values = super(ContractContract, self
)._prepare_recurring_invoices_values()
invoices_values = super()._prepare_recurring_invoices_values()
updated_invoices_values = []
for invoice_val in invoices_values:
invoice_line_values = {}
@ -65,12 +74,11 @@ class ContractContract(models.Model):
contract_line_rec = self.env['contract.line'].\
browse(invoice_line.get('contract_line_id', False))
if contract_line_rec and contract_line_rec.contract_id and\
contract_line_rec.contract_id.invoicing_sales:
order_ids = self.env['sale.order'].search([
('partner_id', '=',
contract_line_rec.contract_id.partner_id.id),
('contract_id', '=', contract_line_rec.contract_id.id),
])
contract_line_rec.contract_id.invoicing_sales and \
contract_line_rec.contract_id.group_by == 'contract':
so_domain = \
contract_line_rec.contract_id.get_sale_order_domain()
order_ids = self.env['sale.order'].search(so_domain)
sale_order_line_product_qty = {}
for order_id in order_ids:
if not order_id.order_line.mapped('invoice_lines'):
@ -117,7 +125,6 @@ class ContractContract(models.Model):
def action_view_sales_orders(self):
res = super(ContractContract, self).action_view_sales_orders()
contracts = self.contract_line_ids.mapped(
'sale_order_line_id.order_id.contract_id'
)
'sale_order_line_id.order_id.contract_id')
res.get('domain')[0][2].extend(contracts)
return res

2
contract_sale_invoicing/views/contract_view.xml

@ -10,6 +10,8 @@
<field name="arch" type="xml">
<field name="recurring_next_date" position="after">
<field name="invoicing_sales"/>
<field name="filter_with"
attrs="{'invisible': [('invoicing_sales', '=', False)]}"/>
<field name="group_by"
attrs="{'invisible': [('invoicing_sales', '=', False)]}"/>
</field>

Loading…
Cancel
Save