|
|
@ -102,6 +102,11 @@ class AccountAnalyticAccount(models.Model): |
|
|
|
('company_id', '=', company_id)] |
|
|
|
return self.env['account.journal'].search(domain, limit=1) |
|
|
|
|
|
|
|
contract_type = fields.Selection( |
|
|
|
selection=[ |
|
|
|
('sale', _('Sale')) |
|
|
|
], default='sale' |
|
|
|
) |
|
|
|
pricelist_id = fields.Many2one( |
|
|
|
comodel_name='product.pricelist', |
|
|
|
string='Pricelist') |
|
|
@ -142,7 +147,7 @@ class AccountAnalyticAccount(models.Model): |
|
|
|
'account.journal', |
|
|
|
string='Journal', |
|
|
|
default=_default_journal, |
|
|
|
domain="[('type', '=', 'sale'),('company_id', '=', company_id)]") |
|
|
|
domain="[('company_id', '=', company_id)]") |
|
|
|
user_id = fields.Many2one( |
|
|
|
comodel_name='res.users', |
|
|
|
string='Responsible', |
|
|
@ -150,6 +155,14 @@ class AccountAnalyticAccount(models.Model): |
|
|
|
default=lambda self: self.env.user, |
|
|
|
) |
|
|
|
|
|
|
|
@api.onchange('contract_type') |
|
|
|
def _onchange_type(self): |
|
|
|
if self.contract_type == 'sale': |
|
|
|
self.journal_id = self.env['account.journal'].search([ |
|
|
|
('type', '=', 'sale'), |
|
|
|
('company_id', '=', self.company_id.id) |
|
|
|
], limit=1) |
|
|
|
|
|
|
|
@api.onchange('partner_id') |
|
|
|
def _onchange_partner_id(self): |
|
|
|
self.pricelist_id = self.partner_id.property_product_pricelist.id |
|
|
@ -236,14 +249,20 @@ class AccountAnalyticAccount(models.Model): |
|
|
|
raise ValidationError( |
|
|
|
_("You must first select a Customer for Contract %s!") % |
|
|
|
contract.name) |
|
|
|
journal = contract.journal_id or self.env['account.journal'].search( |
|
|
|
[('type', '=', 'sale'), |
|
|
|
('company_id', '=', contract.company_id.id)], |
|
|
|
limit=1) |
|
|
|
|
|
|
|
if 'contract_journal' in self.env.context: |
|
|
|
journal = self.env.context['contract_journal'] |
|
|
|
else: |
|
|
|
journal = contract.journal_id or self.env[ |
|
|
|
'account.journal'].search([ |
|
|
|
('type', '=', 'sale'), |
|
|
|
('company_id', '=', contract.company_id.id) |
|
|
|
], limit=1) |
|
|
|
|
|
|
|
if not journal: |
|
|
|
raise ValidationError( |
|
|
|
_("Please define a sale journal for the company '%s'.") % |
|
|
|
(contract.company_id.name or '',)) |
|
|
|
_("Please define a %s journal for the company '%s'.") % |
|
|
|
(contract.type, contract.company_id.name or '',)) |
|
|
|
currency = ( |
|
|
|
contract.pricelist_id.currency_id or |
|
|
|
contract.partner_id.property_product_pricelist.currency_id or |
|
|
|