[FIX] datetime import, first contract number error, keyerror active_id while installing the module
This commit is contained in:
parent
e2fb770bf6
commit
e313d822ab
@ -27,7 +27,7 @@ class PartnerContract(models.Model):
|
|||||||
'res.partner',
|
'res.partner',
|
||||||
string='Contract Partner',
|
string='Contract Partner',
|
||||||
help='Contract partner',
|
help='Contract partner',
|
||||||
default=lambda self: self.env.context['active_id'],
|
default=lambda self: self.env.context.get('active_id'),
|
||||||
required=True
|
required=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,22 +42,22 @@ class PartnerContract(models.Model):
|
|||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
|
|
||||||
datetime_now = datetime.now().strftime("%Y-%m-%d")
|
datetime_now = datetime.datetime.now().strftime("%Y-%m-%d")
|
||||||
vals['name'] = self._calculate_contract_name(datetime_now)
|
vals['name'] = self._calculate_contract_name(datetime_now)
|
||||||
|
|
||||||
return super(PartnerContract, self).create(vals)
|
return super(PartnerContract, self).create(vals)
|
||||||
|
|
||||||
def _calculate_contract_name(self, _date):
|
def _calculate_contract_name(self, _date):
|
||||||
|
|
||||||
contract_date = datetime.strptime(_date, '%Y-%m-%d')
|
contract_date = datetime.datetime.strptime(_date, '%Y-%m-%d')
|
||||||
date_part = contract_date.strftime('%d%m-%y')
|
date_part = contract_date.strftime('%d%m-%y')
|
||||||
|
|
||||||
today_contracts = self.search([
|
today_contracts = self.search([
|
||||||
('date', '=', contract_date.date()),
|
('date', '=', contract_date.date()),
|
||||||
])
|
])
|
||||||
if len(today_contracts) > 0:
|
if len(today_contracts) > 0:
|
||||||
last_contract_number = int(
|
name = today_contracts[-1].name or '0-0-0'
|
||||||
today_contracts[-1].name.split('-')[2]) + 1
|
last_contract_number = int(name.split('-')[2]) + 1
|
||||||
else:
|
else:
|
||||||
last_contract_number = 1
|
last_contract_number = 1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user