Browse Source

[FIX] Fixed contract code

pull/437/head
Nikul Chaudhary 5 years ago
parent
commit
54dd83f6ba
  1. 1
      contract_sale/__manifest__.py
  2. 6
      contract_sale/models/contract.py
  3. 18
      contract_sale/models/sale_order.py
  4. 15
      contract_sale/views/sale_order.xml

1
contract_sale/__manifest__.py

@ -20,6 +20,7 @@
'views/contract_line.xml',
'views/contract_template.xml',
'views/res_partner_view.xml',
'views/sale_order.xml',
],
'license': 'AGPL-3',
'installable': True,

6
contract_sale/models/contract.py

@ -11,10 +11,12 @@ class ContractContract(models.Model):
_prepare_recurring_invoices_values(date_ref=date_ref)
return invoices_values
@api.depends('contract_line_ids')
def _compute_sale_order_count(self):
super(ContractContract, self)._compute_sale_order_count()
contract_count = self.contract_line_ids.\
mapped('sale_order_line_id.order_id.contract_id')
contract_count = len(
self.contract_line_ids.
mapped('sale_order_line_id.order_id.contract_id')) or 0
self.sale_order_count += contract_count
@api.multi

18
contract_sale/models/sale_order.py

@ -7,21 +7,5 @@ class SaleOrder(models.Model):
contract_id = fields.Many2one(
comodel_name="contract.contract",
string="Contract"
string="Contract",
)
@api.multi
def action_confirm(self):
res = super(SaleOrder, self).action_confirm()
invoice_ids = self.env['account.invoice'].search([
('partner_id', '=', self.partner_id.id),
('old_contract_id', '=', self.contract_id.id),
('state', '=', 'draft')])
for invoice_id in invoice_ids:
for order_line in self.order_line:
for invoice_line in invoice_id.invoice_line_ids:
if order_line.product_id.id == invoice_line.product_id.id:
invoice_line.quantity += order_line.product_uom_qty
self.action_invoice_create()
return res

15
contract_sale/views/sale_order.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_order_form_form_view" model="ir.ui.view">
<field name="name">sale.order.form.view</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="contract_id" domain="[('partner_id', '=', partner_id)]"/>
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save