2
0

[IMP] account_move_budget: black, isort

This commit is contained in:
hveficent 2019-12-30 11:26:37 +01:00 committed by David Jaen
parent 3cd631d74d
commit 8db337680a
7 changed files with 113 additions and 141 deletions

View File

@ -1,3 +1 @@
from . import models from . import models

View File

@ -7,15 +7,11 @@
"version": "12.0.1.0.0", "version": "12.0.1.0.0",
"category": "Accounting & Finance", "category": "Accounting & Finance",
"website": "https://github.com/OCA/account-financial-tools", "website": "https://github.com/OCA/account-financial-tools",
"author": "Eficent, " "author": "Eficent, " "Odoo Community Association (OCA)",
"Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"application": False, "application": False,
"installable": True, "installable": True,
"depends": [ "depends": ["account", "date_range"],
"account",
"date_range",
],
"data": [ "data": [
"security/ir.model.access.csv", "security/ir.model.access.csv",
"views/account_move_budget_line_views.xml", "views/account_move_budget_line_views.xml",

View File

@ -1,3 +1,2 @@
from . import account_move_budget from . import account_move_budget
from . import account_move_budget_line from . import account_move_budget_line

View File

@ -8,51 +8,30 @@ from odoo import _, api, fields, models
class AccountMoveBudget(models.Model): class AccountMoveBudget(models.Model):
_name = "account.move.budget" _name = "account.move.budget"
_description = "Account Move Budget" _description = "Account Move Budget"
_inherit = ['mail.thread', 'mail.activity.mixin'] _inherit = ["mail.thread", "mail.activity.mixin"]
@api.model @api.model
def _default_company(self): def _default_company(self):
return self.env['res.company']. \ return self.env["res.company"]._company_default_get("mis.budget")
_company_default_get('mis.budget')
name = fields.Char( name = fields.Char(required=True, track_visibility="onchange")
required=True, description = fields.Char(track_visibility="onchange")
track_visibility='onchange', date_range_id = fields.Many2one(comodel_name="date.range", string="Date range")
)
description = fields.Char(
track_visibility='onchange',
)
date_range_id = fields.Many2one(
comodel_name='date.range',
string='Date range',
)
date_from = fields.Date( date_from = fields.Date(
required=True, required=True, string="From Date", track_visibility="onchange"
string='From Date',
track_visibility='onchange',
)
date_to = fields.Date(
required=True,
string='To Date',
track_visibility='onchange',
) )
date_to = fields.Date(required=True, string="To Date", track_visibility="onchange")
state = fields.Selection( state = fields.Selection(
[('draft', 'Draft'), [("draft", "Draft"), ("confirmed", "Confirmed"), ("cancelled", "Cancelled")],
('confirmed', 'Confirmed'),
('cancelled', 'Cancelled')],
required=True, required=True,
default='draft', default="draft",
track_visibility='onchange', track_visibility="onchange",
) )
line_ids = fields.One2many( line_ids = fields.One2many(
comodel_name='account.move.budget.line', comodel_name="account.move.budget.line", inverse_name="budget_id", copy=True
inverse_name='budget_id',
copy=True,
) )
company_id = fields.Many2one( company_id = fields.Many2one(
comodel_name='res.company', comodel_name="res.company", string="Company", default=_default_company
string='Company',
default=_default_company,
) )
@api.multi @api.multi
@ -60,36 +39,38 @@ class AccountMoveBudget(models.Model):
self.ensure_one() self.ensure_one()
if default is None: if default is None:
default = {} default = {}
if 'name' not in default: if "name" not in default:
default['name'] = _("%s (copy)") % self.name default["name"] = _("%s (copy)") % self.name
return super(AccountMoveBudget, self).copy(default=default) return super(AccountMoveBudget, self).copy(default=default)
@api.onchange('date_range_id') @api.onchange("date_range_id")
def _onchange_date_range(self): def _onchange_date_range(self):
for rec in self: for rec in self:
if rec.date_range_id: if rec.date_range_id:
rec.date_from = rec.date_range_id.date_start rec.date_from = rec.date_range_id.date_start
rec.date_to = rec.date_range_id.date_end rec.date_to = rec.date_range_id.date_end
@api.onchange('date_from', 'date_to') @api.onchange("date_from", "date_to")
def _onchange_dates(self): def _onchange_dates(self):
for rec in self: for rec in self:
if rec.date_range_id: if rec.date_range_id:
if rec.date_from != rec.date_range_id.date_start or \ if (
rec.date_to != rec.date_range_id.date_end: rec.date_from != rec.date_range_id.date_start
or rec.date_to != rec.date_range_id.date_end
):
rec.date_range_id = False rec.date_range_id = False
@api.multi @api.multi
def action_draft(self): def action_draft(self):
for rec in self: for rec in self:
rec.state = 'draft' rec.state = "draft"
@api.multi @api.multi
def action_cancel(self): def action_cancel(self):
for rec in self: for rec in self:
rec.state = 'cancelled' rec.state = "cancelled"
@api.multi @api.multi
def action_confirm(self): def action_confirm(self):
for rec in self: for rec in self:
rec.state = 'confirmed' rec.state = "confirmed"

View File

@ -11,77 +11,62 @@ class AccountMoveBudgetLine(models.Model):
_order = "date desc, id desc" _order = "date desc, id desc"
budget_id = fields.Many2one( budget_id = fields.Many2one(
comodel_name='account.move.budget', comodel_name="account.move.budget",
string="Budget", string="Budget",
required=True, required=True,
ondelete='cascade', ondelete="cascade",
index=True, index=True,
) )
name = fields.Char(string="Label") name = fields.Char(string="Label")
debit = fields.Monetary( debit = fields.Monetary(default=0.0, currency_field="company_currency_id")
default=0.0, credit = fields.Monetary(default=0.0, currency_field="company_currency_id")
currency_field='company_currency_id',
)
credit = fields.Monetary(
default=0.0,
currency_field='company_currency_id'
)
balance = fields.Monetary( balance = fields.Monetary(
compute='_compute_store_balance', compute="_compute_store_balance",
store=True, store=True,
currency_field='company_currency_id', currency_field="company_currency_id",
help="Technical field holding the debit - " help="Technical field holding the debit - "
"credit in order to open meaningful " "credit in order to open meaningful "
"graph views from reports", "graph views from reports",
) )
company_currency_id = fields.Many2one( company_currency_id = fields.Many2one(
'res.currency', "res.currency",
related='company_id.currency_id', related="company_id.currency_id",
string="Company Currency", string="Company Currency",
readonly=True, readonly=True,
help='Utility field to express amount currency', help="Utility field to express amount currency",
store=True, store=True,
) )
account_id = fields.Many2one( account_id = fields.Many2one(
'account.account', "account.account",
string='Account', string="Account",
required=True, required=True,
index=True, index=True,
ondelete="cascade", ondelete="cascade",
domain=[('deprecated', '=', False)], domain=[("deprecated", "=", False)],
default=lambda self: self._context.get('account_id', False), default=lambda self: self._context.get("account_id", False),
)
date = fields.Date(
string='Date',
index=True,
required=True,
) )
date = fields.Date(string="Date", index=True, required=True)
analytic_account_id = fields.Many2one( analytic_account_id = fields.Many2one(
'account.analytic.account', "account.analytic.account", string="Analytic Account"
string='Analytic Account',
) )
company_id = fields.Many2one( company_id = fields.Many2one(
'res.company', "res.company",
related='account_id.company_id', related="account_id.company_id",
string='Company', string="Company",
store=True, store=True,
readonly=True, readonly=True,
) )
partner_id = fields.Many2one( partner_id = fields.Many2one("res.partner", string="Partner", ondelete="restrict")
'res.partner',
string='Partner',
ondelete='restrict',
)
@api.depends('debit', 'credit') @api.depends("debit", "credit")
def _compute_store_balance(self): def _compute_store_balance(self):
for line in self: for line in self:
line.balance = line.debit - line.credit line.balance = line.debit - line.credit
@api.constrains('date') @api.constrains("date")
def _constraint_date(self): def _constraint_date(self):
for rec in self: for rec in self:
if rec.budget_id.date_from > rec.date or \ if rec.budget_id.date_from > rec.date or rec.budget_id.date_to < rec.date:
rec.budget_id.date_to < rec.date: raise ValidationError(
raise ValidationError(_('The date must be within the ' _("The date must be within the " "budget period.")
'budget period.')) )

View File

@ -2,26 +2,26 @@
<!-- Copyright 2019 Eficent Business and IT Consulting Services, S.L. <!-- Copyright 2019 Eficent Business and IT Consulting Services, S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo> <odoo>
<record id="view_account_move_budget_line_tree" model="ir.ui.view"> <record id="view_account_move_budget_line_tree" model="ir.ui.view">
<field name="name">Account Move Budget Line tree</field> <field name="name">Account Move Budget Line tree</field>
<field name="model">account.move.budget.line</field> <field name="model">account.move.budget.line</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree editable="top"> <tree editable="top">
<field name="account_id"/> <field name="account_id" />
<field name="date"/> <field name="date" />
<field name="debit"/> <field name="debit" />
<field name="credit"/> <field name="credit" />
<field name="balance"/> <field name="balance" />
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/> <field
<field name="partner_id"/> name="analytic_account_id"
<field name="name"/> groups="analytic.group_analytic_accounting"
<field name="company_id" groups="base.group_multi_company"/> />
<field name="partner_id" />
<field name="name" />
<field name="company_id" groups="base.group_multi_company" />
</tree> </tree>
</field> </field>
</record> </record>
<record model="ir.actions.act_window" id="account_move_budget_line_act_window"> <record model="ir.actions.act_window" id="account_move_budget_line_act_window">
<field name="name">Budget Items</field> <field name="name">Budget Items</field>
<field name="res_model">account.move.budget.line</field> <field name="res_model">account.move.budget.line</field>
@ -29,5 +29,4 @@
<field name="domain">[('budget_id', '=', active_id)]</field> <field name="domain">[('budget_id', '=', active_id)]</field>
<field name="context">{'default_budget_id': active_id}</field> <field name="context">{'default_budget_id': active_id}</field>
</record> </record>
</odoo> </odoo>

View File

@ -1,80 +1,93 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2019 ACSONE SA/NV <!-- Copyright 2019 ACSONE SA/NV
Copyright 2019 Eficent Business and IT Consulting Services, S.L. Copyright 2019 Eficent Business and IT Consulting Services, S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo> <odoo>
<record model="ir.ui.view" id="account_move_budget_form_view"> <record model="ir.ui.view" id="account_move_budget_form_view">
<field name="name">account.move.budget.form</field> <field name="name">account.move.budget.form</field>
<field name="model">account.move.budget</field> <field name="model">account.move.budget</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form> <form>
<header> <header>
<button name="action_draft" string="Set draft" type="object" attrs="{'invisible': [('state', '=', 'draft')]}"/> <button
<button name="action_confirm" string="Confirm" type="object" attrs="{'invisible': [('state', '!=', 'draft')]}" class="oe_highlight"/> name="action_draft"
<button name="action_cancel" string="Cancel" type="object" attrs="{'invisible': [('state', '=', 'cancelled')]}"/> string="Set draft"
<field name="state" widget="statusbar"/> type="object"
attrs="{'invisible': [('state', '=', 'draft')]}"
/>
<button
name="action_confirm"
string="Confirm"
type="object"
attrs="{'invisible': [('state', '!=', 'draft')]}"
class="oe_highlight"
/>
<button
name="action_cancel"
string="Cancel"
type="object"
attrs="{'invisible': [('state', '=', 'cancelled')]}"
/>
<field name="state" widget="statusbar" />
</header> </header>
<sheet> <sheet>
<div class="oe_button_box" name="button_box"> <div class="oe_button_box" name="button_box">
<button name="%(account_move_budget_line_act_window)d" <button
type="action" name="%(account_move_budget_line_act_window)d"
class="oe_stat_button" type="action"
icon="fa-bars" class="oe_stat_button"
string="Budget Lines"/> icon="fa-bars"
string="Budget Lines"
/>
</div> </div>
<div class="oe_title"> <div class="oe_title">
<div class="oe_edit_only"> <div class="oe_edit_only">
<label for="name"/> <label for="name" />
</div> </div>
<h1> <h1>
<field name="name" placeholder="Name"/> <field name="name" placeholder="Name" />
</h1> </h1>
<field name="description"/> <field name="description" />
</div> </div>
<group name="company"> <group name="company">
<field name="company_id" groups="base.group_multi_company"/> <field name="company_id" groups="base.group_multi_company" />
</group> </group>
<group name="dates"> <group name="dates">
<field name="date_range_id"/> <field name="date_range_id" />
<field name="date_from"/> <field name="date_from" />
<field name="date_to"/> <field name="date_to" />
</group> </group>
</sheet> </sheet>
<div class="oe_chatter"> <div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/> <field name="message_follower_ids" widget="mail_followers" />
<field name="activity_ids" widget="mail_activity"/> <field name="activity_ids" widget="mail_activity" />
<field name="message_ids" widget="mail_thread"/> <field name="message_ids" widget="mail_thread" />
</div> </div>
</form> </form>
</field> </field>
</record> </record>
<record model="ir.ui.view" id="account_move_budget_search_view"> <record model="ir.ui.view" id="account_move_budget_search_view">
<field name="name">account.move.budget.search</field> <field name="name">account.move.budget.search</field>
<field name="model">account.move.budget</field> <field name="model">account.move.budget</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<search> <search>
<field name="name"/> <field name="name" />
<field name="state"/> <field name="state" />
</search> </search>
</field> </field>
</record> </record>
<record model="ir.ui.view" id="account_move_budget_tree_view"> <record model="ir.ui.view" id="account_move_budget_tree_view">
<field name="name">account.move.budget.tree</field> <field name="name">account.move.budget.tree</field>
<field name="model">account.move.budget</field> <field name="model">account.move.budget</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree> <tree>
<field name="name"/> <field name="name" />
<field name="date_from"/> <field name="date_from" />
<field name="date_to"/> <field name="date_to" />
<field name="state"/> <field name="state" />
</tree> </tree>
</field> </field>
</record> </record>
<record model="ir.actions.act_window" id="account_move_budget_act_window"> <record model="ir.actions.act_window" id="account_move_budget_act_window">
<field name="name">Account Move Budgets</field> <field name="name">Account Move Budgets</field>
<field name="res_model">account.move.budget</field> <field name="res_model">account.move.budget</field>
@ -82,11 +95,12 @@
<field name="domain">[]</field> <field name="domain">[]</field>
<field name="context">{}</field> <field name="context">{}</field>
</record> </record>
<record model="ir.ui.menu" id="account_move_budget_menu"> <record model="ir.ui.menu" id="account_move_budget_menu">
<field name="name">Account Move Budgets</field> <field name="name">Account Move Budgets</field>
<field name="parent_id" ref="account.menu_finance_entries_accounting_entries"/> <field
<field name="action" ref="account_move_budget_act_window"/> name="parent_id"
ref="account.menu_finance_entries_accounting_miscellaneous"
/>
<field name="action" ref="account_move_budget_act_window" />
</record> </record>
</odoo> </odoo>