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

View File

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

View File

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

View File

@ -8,51 +8,30 @@ from odoo import _, api, fields, models
class AccountMoveBudget(models.Model):
_name = "account.move.budget"
_description = "Account Move Budget"
_inherit = ['mail.thread', 'mail.activity.mixin']
_inherit = ["mail.thread", "mail.activity.mixin"]
@api.model
def _default_company(self):
return self.env['res.company']. \
_company_default_get('mis.budget')
return self.env["res.company"]._company_default_get("mis.budget")
name = fields.Char(
required=True,
track_visibility='onchange',
)
description = fields.Char(
track_visibility='onchange',
)
date_range_id = fields.Many2one(
comodel_name='date.range',
string='Date range',
)
name = fields.Char(required=True, track_visibility="onchange")
description = fields.Char(track_visibility="onchange")
date_range_id = fields.Many2one(comodel_name="date.range", string="Date range")
date_from = fields.Date(
required=True,
string='From Date',
track_visibility='onchange',
)
date_to = fields.Date(
required=True,
string='To Date',
track_visibility='onchange',
required=True, string="From Date", track_visibility="onchange"
)
date_to = fields.Date(required=True, string="To Date", track_visibility="onchange")
state = fields.Selection(
[('draft', 'Draft'),
('confirmed', 'Confirmed'),
('cancelled', 'Cancelled')],
[("draft", "Draft"), ("confirmed", "Confirmed"), ("cancelled", "Cancelled")],
required=True,
default='draft',
track_visibility='onchange',
default="draft",
track_visibility="onchange",
)
line_ids = fields.One2many(
comodel_name='account.move.budget.line',
inverse_name='budget_id',
copy=True,
comodel_name="account.move.budget.line", inverse_name="budget_id", copy=True
)
company_id = fields.Many2one(
comodel_name='res.company',
string='Company',
default=_default_company,
comodel_name="res.company", string="Company", default=_default_company
)
@api.multi
@ -60,36 +39,38 @@ class AccountMoveBudget(models.Model):
self.ensure_one()
if default is None:
default = {}
if 'name' not in default:
default['name'] = _("%s (copy)") % self.name
if "name" not in default:
default["name"] = _("%s (copy)") % self.name
return super(AccountMoveBudget, self).copy(default=default)
@api.onchange('date_range_id')
@api.onchange("date_range_id")
def _onchange_date_range(self):
for rec in self:
if rec.date_range_id:
rec.date_from = rec.date_range_id.date_start
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):
for rec in self:
if rec.date_range_id:
if rec.date_from != rec.date_range_id.date_start or \
rec.date_to != rec.date_range_id.date_end:
if (
rec.date_from != rec.date_range_id.date_start
or rec.date_to != rec.date_range_id.date_end
):
rec.date_range_id = False
@api.multi
def action_draft(self):
for rec in self:
rec.state = 'draft'
rec.state = "draft"
@api.multi
def action_cancel(self):
for rec in self:
rec.state = 'cancelled'
rec.state = "cancelled"
@api.multi
def action_confirm(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"
budget_id = fields.Many2one(
comodel_name='account.move.budget',
comodel_name="account.move.budget",
string="Budget",
required=True,
ondelete='cascade',
ondelete="cascade",
index=True,
)
name = fields.Char(string="Label")
debit = fields.Monetary(
default=0.0,
currency_field='company_currency_id',
)
credit = fields.Monetary(
default=0.0,
currency_field='company_currency_id'
)
debit = fields.Monetary(default=0.0, currency_field="company_currency_id")
credit = fields.Monetary(default=0.0, currency_field="company_currency_id")
balance = fields.Monetary(
compute='_compute_store_balance',
compute="_compute_store_balance",
store=True,
currency_field='company_currency_id',
currency_field="company_currency_id",
help="Technical field holding the debit - "
"credit in order to open meaningful "
"graph views from reports",
)
company_currency_id = fields.Many2one(
'res.currency',
related='company_id.currency_id',
"res.currency",
related="company_id.currency_id",
string="Company Currency",
readonly=True,
help='Utility field to express amount currency',
help="Utility field to express amount currency",
store=True,
)
account_id = fields.Many2one(
'account.account',
string='Account',
"account.account",
string="Account",
required=True,
index=True,
ondelete="cascade",
domain=[('deprecated', '=', False)],
default=lambda self: self._context.get('account_id', False),
)
date = fields.Date(
string='Date',
index=True,
required=True,
domain=[("deprecated", "=", False)],
default=lambda self: self._context.get("account_id", False),
)
date = fields.Date(string="Date", index=True, required=True)
analytic_account_id = fields.Many2one(
'account.analytic.account',
string='Analytic Account',
"account.analytic.account", string="Analytic Account"
)
company_id = fields.Many2one(
'res.company',
related='account_id.company_id',
string='Company',
"res.company",
related="account_id.company_id",
string="Company",
store=True,
readonly=True,
)
partner_id = fields.Many2one(
'res.partner',
string='Partner',
ondelete='restrict',
)
partner_id = fields.Many2one("res.partner", string="Partner", ondelete="restrict")
@api.depends('debit', 'credit')
@api.depends("debit", "credit")
def _compute_store_balance(self):
for line in self:
line.balance = line.debit - line.credit
@api.constrains('date')
@api.constrains("date")
def _constraint_date(self):
for rec in self:
if rec.budget_id.date_from > rec.date or \
rec.budget_id.date_to < rec.date:
raise ValidationError(_('The date must be within the '
'budget period.'))
if rec.budget_id.date_from > rec.date or rec.budget_id.date_to < rec.date:
raise ValidationError(
_("The date must be within the " "budget period.")
)

View File

@ -2,26 +2,26 @@
<!-- Copyright 2019 Eficent Business and IT Consulting Services, S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="view_account_move_budget_line_tree" model="ir.ui.view">
<field name="name">Account Move Budget Line tree</field>
<field name="model">account.move.budget.line</field>
<field name="arch" type="xml">
<tree editable="top">
<field name="account_id"/>
<field name="date"/>
<field name="debit"/>
<field name="credit"/>
<field name="balance"/>
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
<field name="partner_id"/>
<field name="name"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="account_id" />
<field name="date" />
<field name="debit" />
<field name="credit" />
<field name="balance" />
<field
name="analytic_account_id"
groups="analytic.group_analytic_accounting"
/>
<field name="partner_id" />
<field name="name" />
<field name="company_id" groups="base.group_multi_company" />
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="account_move_budget_line_act_window">
<field name="name">Budget Items</field>
<field name="res_model">account.move.budget.line</field>
@ -29,5 +29,4 @@
<field name="domain">[('budget_id', '=', active_id)]</field>
<field name="context">{'default_budget_id': active_id}</field>
</record>
</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 Eficent Business and IT Consulting Services, S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.ui.view" id="account_move_budget_form_view">
<field name="name">account.move.budget.form</field>
<field name="model">account.move.budget</field>
<field name="arch" type="xml">
<form>
<header>
<button name="action_draft" string="Set draft" 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"/>
<button
name="action_draft"
string="Set draft"
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>
<sheet>
<div class="oe_button_box" name="button_box">
<button name="%(account_move_budget_line_act_window)d"
<button
name="%(account_move_budget_line_act_window)d"
type="action"
class="oe_stat_button"
icon="fa-bars"
string="Budget Lines"/>
string="Budget Lines"
/>
</div>
<div class="oe_title">
<div class="oe_edit_only">
<label for="name"/>
<label for="name" />
</div>
<h1>
<field name="name" placeholder="Name"/>
<field name="name" placeholder="Name" />
</h1>
<field name="description"/>
<field name="description" />
</div>
<group name="company">
<field name="company_id" groups="base.group_multi_company"/>
<field name="company_id" groups="base.group_multi_company" />
</group>
<group name="dates">
<field name="date_range_id"/>
<field name="date_from"/>
<field name="date_to"/>
<field name="date_range_id" />
<field name="date_from" />
<field name="date_to" />
</group>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="activity_ids" widget="mail_activity"/>
<field name="message_ids" widget="mail_thread"/>
<field name="message_follower_ids" widget="mail_followers" />
<field name="activity_ids" widget="mail_activity" />
<field name="message_ids" widget="mail_thread" />
</div>
</form>
</field>
</record>
<record model="ir.ui.view" id="account_move_budget_search_view">
<field name="name">account.move.budget.search</field>
<field name="model">account.move.budget</field>
<field name="arch" type="xml">
<search>
<field name="name"/>
<field name="state"/>
<field name="name" />
<field name="state" />
</search>
</field>
</record>
<record model="ir.ui.view" id="account_move_budget_tree_view">
<field name="name">account.move.budget.tree</field>
<field name="model">account.move.budget</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="date_from"/>
<field name="date_to"/>
<field name="state"/>
<field name="name" />
<field name="date_from" />
<field name="date_to" />
<field name="state" />
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="account_move_budget_act_window">
<field name="name">Account Move Budgets</field>
<field name="res_model">account.move.budget</field>
@ -82,11 +95,12 @@
<field name="domain">[]</field>
<field name="context">{}</field>
</record>
<record model="ir.ui.menu" id="account_move_budget_menu">
<field name="name">Account Move Budgets</field>
<field name="parent_id" ref="account.menu_finance_entries_accounting_entries"/>
<field name="action" ref="account_move_budget_act_window"/>
<field
name="parent_id"
ref="account.menu_finance_entries_accounting_miscellaneous"
/>
<field name="action" ref="account_move_budget_act_window" />
</record>
</odoo>