Browse Source

[9.0][IMP] Add type to analytic account / contract

pull/96/head
Stefan Becker 7 years ago
parent
commit
8d58f6d6fc
  1. 33
      contract/models/contract.py
  2. 14
      contract/views/contract.xml

33
contract/models/contract.py

@ -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

14
contract/views/contract.xml

@ -24,6 +24,16 @@
<button name="action_contract_send" type="object" string="Send by Email" groups="base.group_user"/>
</header>
</xpath>
<xpath expr='//field[@name="code"]' position='before'>
<field name="contract_type"/>
</xpath>
<field name="partner_id" position="attributes">
<attribute name="domain">[('customer', '=', True)]</attribute>
<attribute name="context">{
'default_customer': True,
'default_supplier': False
}</attribute>
</field>
<notebook position="before">
<separator string="Recurring Invoices" attrs="{'invisible': [('recurring_invoices','!=',True)]}"/>
<div>
@ -53,7 +63,7 @@
<div attrs="{'invisible': [('recurring_invoices','=',False)]}">
<field name="recurring_invoice_line_ids">
<tree string="Account Analytic Lines" editable="bottom">
<field name="product_id"/>
<field name="product_id" domain="[('sale_ok', '=', True)]"/>
<field name="name"/>
<field name="quantity"/>
<field name="uom_id"/>
@ -107,7 +117,7 @@
<field name="res_model">account.analytic.account</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain"/> <!-- This is for resetting the field when migrating from v8 -->
<field name="domain">[('contract_type', '=', 'sale')]</field>
<field name="context">{'search_default_active':1, 'search_default_recurring_invoices':1}</field>
<field name="search_view_id" ref="analytic.view_account_analytic_account_search"/>
<field name="help" type="html">

Loading…
Cancel
Save