|
@ -9,9 +9,11 @@ class ContractContract(models.Model): |
|
|
|
|
|
|
|
|
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 ' |
|
|
|
|
|
'in contract invoice creation.', |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
help='Include sales to invoice on the contract invoice.') |
|
|
|
|
|
group_by = fields.Selection([ |
|
|
|
|
|
('analytic_account', 'Analytic Account'), |
|
|
|
|
|
('contract', 'Contract')], |
|
|
|
|
|
default='analytic_account', string='Group By') |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def _recurring_create_invoice(self, date_ref=False): |
|
|
def _recurring_create_invoice(self, date_ref=False): |
|
@ -31,12 +33,29 @@ class ContractContract(models.Model): |
|
|
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] |
|
|
|
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _prepare_invoice_line_dict(self, contract_line_rec, invoice_line, |
|
|
|
|
|
remain_qty): |
|
|
|
|
|
return { |
|
|
|
|
|
'invoice_id': False, |
|
|
|
|
|
'uom_id': contract_line_rec.uom_id.id, |
|
|
|
|
|
'product_id': invoice_line.get('product_id'), |
|
|
|
|
|
'quantity': remain_qty or 0, |
|
|
|
|
|
'discount': contract_line_rec.discount, |
|
|
|
|
|
'contract_line_id': contract_line_rec.id, |
|
|
|
|
|
'name': contract_line_rec.name, |
|
|
|
|
|
'account_analytic_id': False, |
|
|
|
|
|
'price_unit': contract_line_rec.price_unit |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def _prepare_recurring_invoices_values(self, date_ref=False): |
|
|
def _prepare_recurring_invoices_values(self, date_ref=False): |
|
|
invoices_values = super(ContractContract, self |
|
|
invoices_values = super(ContractContract, self |
|
|
)._prepare_recurring_invoices_values() |
|
|
)._prepare_recurring_invoices_values() |
|
|
|
|
|
updated_invoices_values = [] |
|
|
for invoice_val in invoices_values: |
|
|
for invoice_val in invoices_values: |
|
|
invoice_line_values = {} |
|
|
invoice_line_values = {} |
|
|
|
|
|
invoice_line_list = [] |
|
|
for invoice_line in invoice_val.get('invoice_line_ids', []): |
|
|
for invoice_line in invoice_val.get('invoice_line_ids', []): |
|
|
invoice_line = invoice_line[2] or {} |
|
|
invoice_line = invoice_line[2] or {} |
|
|
contract_line_rec = self.env['contract.line'].\ |
|
|
contract_line_rec = self.env['contract.line'].\ |
|
@ -54,32 +73,33 @@ class ContractContract(models.Model): |
|
|
for line in order_id.order_line: |
|
|
for line in order_id.order_line: |
|
|
if sale_order_line_product_qty.\ |
|
|
if sale_order_line_product_qty.\ |
|
|
get(line.product_id.id): |
|
|
get(line.product_id.id): |
|
|
sale_order_line_product_qty[line. |
|
|
|
|
|
product_id.id] += line.product_uom_qty |
|
|
|
|
|
|
|
|
sale_order_line_product_qty[ |
|
|
|
|
|
line.product_id.id |
|
|
|
|
|
] += line.product_uom_qty |
|
|
else: |
|
|
else: |
|
|
sale_order_line_product_qty[line. |
|
|
|
|
|
product_id.id] = line.product_uom_qty |
|
|
|
|
|
|
|
|
sale_order_line_product_qty[ |
|
|
|
|
|
line.product_id.id |
|
|
|
|
|
] = line.product_uom_qty |
|
|
if invoice_line.get('product_id' |
|
|
if invoice_line.get('product_id' |
|
|
) in sale_order_line_product_qty: |
|
|
) in sale_order_line_product_qty: |
|
|
if sale_order_line_product_qty.get(line.product_id.id |
|
|
|
|
|
|
|
|
if sale_order_line_product_qty.\ |
|
|
|
|
|
get(line.product_id.id |
|
|
) > invoice_line.get('quantity'): |
|
|
) > invoice_line.get('quantity'): |
|
|
remain_qty = sale_order_line_product_qty.\ |
|
|
remain_qty = sale_order_line_product_qty.\ |
|
|
get(invoice_line.get('product_id') |
|
|
get(invoice_line.get('product_id') |
|
|
) - invoice_line.get('quantity') or 0 |
|
|
) - invoice_line.get('quantity') or 0 |
|
|
invoice_line_values = { |
|
|
|
|
|
'invoice_id': False, |
|
|
|
|
|
'uom_id': contract_line_rec.uom_id.id, |
|
|
|
|
|
'product_id': invoice_line.get('product_id'), |
|
|
|
|
|
'quantity': remain_qty or 0, |
|
|
|
|
|
'discount': contract_line_rec.discount, |
|
|
|
|
|
'contract_line_id': contract_line_rec.id, |
|
|
|
|
|
'name': contract_line_rec.name, |
|
|
|
|
|
'account_analytic_id': False, |
|
|
|
|
|
'price_unit': contract_line_rec.price_unit |
|
|
|
|
|
} |
|
|
|
|
|
invoice_val['invoice_line_ids' |
|
|
|
|
|
].append((0, 0, invoice_line_values)) |
|
|
|
|
|
return invoices_values |
|
|
|
|
|
|
|
|
invoice_line_values =\ |
|
|
|
|
|
self._prepare_invoice_line_dict( |
|
|
|
|
|
contract_line_rec, invoice_line, remain_qty |
|
|
|
|
|
) or {} |
|
|
|
|
|
invoice_line_list.append(invoice_line_values) |
|
|
|
|
|
sale_order_line_product_qty.\ |
|
|
|
|
|
pop(invoice_line.get('product_id')) |
|
|
|
|
|
invoice_val['invoice_line_ids'] +=\ |
|
|
|
|
|
[(0, 0, invoice_line_val |
|
|
|
|
|
)for invoice_line_val in invoice_line_list] |
|
|
|
|
|
updated_invoices_values.append(invoice_val) |
|
|
|
|
|
return updated_invoices_values |
|
|
|
|
|
|
|
|
@api.depends('contract_line_ids') |
|
|
@api.depends('contract_line_ids') |
|
|
def _compute_sale_order_count(self): |
|
|
def _compute_sale_order_count(self): |
|
|