Browse Source

[FIX] - don't play onchange date_start for old lines on contract template change

[FIX] - Fix stop post message

[FIX] - Fix sale_contract_count should count all partner contract

[FIX] - set recurring_next_date to False if contract line stoped at last date invoiced

[FIX] - Group by next_invoice also considers dates in the past
13.0-mig-contract
sbejaoui 6 years ago
committed by Administrator
parent
commit
4c36e1a3f4
  1. 2
      contract/models/contract.py
  2. 17
      contract/models/contract_line.py
  3. 4
      contract/models/res_partner.py
  4. 6
      contract/tests/test_contract.py
  5. 2
      contract/views/contract.xml

2
contract/models/contract.py

@ -183,7 +183,6 @@ class AccountAnalyticAccount(models.Model):
) )
): ):
self[field_name] = self.contract_template_id[field_name] self[field_name] = self.contract_template_id[field_name]
self.recurring_invoice_line_ids._onchange_date_start()
@api.onchange('partner_id') @api.onchange('partner_id')
def _onchange_partner_id(self): def _onchange_partner_id(self):
@ -225,6 +224,7 @@ class AccountAnalyticAccount(models.Model):
contract_line contract_line
) )
new_lines += contract_line_model.new(vals) new_lines += contract_line_model.new(vals)
new_lines._onchange_date_start()
return new_lines return new_lines
@api.multi @api.multi

17
contract/models/contract_line.py

@ -658,8 +658,16 @@ class AccountAnalyticInvoiceLine(models.Model):
rec.cancel() rec.cancel()
else: else:
if not rec.date_end or rec.date_end > date_end: if not rec.date_end or rec.date_end > date_end:
if post_message:
old_date_end = rec.date_end old_date_end = rec.date_end
values = {
'date_end': date_end,
'is_auto_renew': False,
'manual_renew_needed': manual_renew_needed,
}
if rec.last_date_invoiced == date_end:
values['recurring_next_date'] = False
rec.write(values)
if post_message:
msg = _( msg = _(
"""Contract line for <strong>{product}</strong> """Contract line for <strong>{product}</strong>
stopped: <br/> stopped: <br/>
@ -671,13 +679,6 @@ class AccountAnalyticInvoiceLine(models.Model):
) )
) )
rec.contract_id.message_post(body=msg) rec.contract_id.message_post(body=msg)
rec.write(
{
'date_end': date_end,
'is_auto_renew': False,
"manual_renew_needed": manual_renew_needed,
}
)
else: else:
rec.write( rec.write(
{ {

4
contract/models/res_partner.py

@ -16,14 +16,10 @@ class ResPartner(models.Model):
def _compute_contract_count(self): def _compute_contract_count(self):
contract_model = self.env['account.analytic.account'] contract_model = self.env['account.analytic.account']
today = fields.Date.today()
fetch_data = contract_model.read_group( fetch_data = contract_model.read_group(
[ [
('recurring_invoices', '=', True), ('recurring_invoices', '=', True),
('partner_id', 'child_of', self.ids), ('partner_id', 'child_of', self.ids),
'|',
('date_end', '=', False),
('date_end', '>=', today),
], ],
['partner_id', 'contract_type'], ['partner_id', 'contract_type'],
['partner_id', 'contract_type'], ['partner_id', 'contract_type'],

6
contract/tests/test_contract.py

@ -1807,3 +1807,9 @@ class TestContract(TestContractBase):
self.contract.recurring_invoice_line_ids.cancel() self.contract.recurring_invoice_line_ids.cancel()
self.contract.recurring_invoice_line_ids.unlink() self.contract.recurring_invoice_line_ids.unlink()
self.assertFalse(self.contract.recurring_create_invoice()) self.assertFalse(self.contract.recurring_create_invoice())
def test_stop_at_last_date_invoiced(self):
self.contract.recurring_create_invoice()
self.assertTrue(self.acct_line.recurring_next_date)
self.acct_line.stop(self.acct_line.last_date_invoiced)
self.assertFalse(self.acct_line.recurring_next_date)

2
contract/views/contract.xml

@ -204,7 +204,7 @@
<group expand="0" string="Group By..."> <group expand="0" string="Group By...">
<filter name="next_invoice" <filter name="next_invoice"
string="Next Invoice" string="Next Invoice"
domain="[('recurring_next_date', '&gt;=', time.strftime('%Y-%m-%d'))]"
domain="[('recurring_next_date', '!=', False)]"
context="{'group_by':'recurring_next_date'}" context="{'group_by':'recurring_next_date'}"
/> />
<filter name="date_end" <filter name="date_end"

Loading…
Cancel
Save