[IMP] pre-commit: first run on whole repo

This commit is contained in:
Kevin Khao
2021-11-26 18:54:38 +03:00
parent a04b8980e1
commit 167aefee13
289 changed files with 6020 additions and 4170 deletions

View File

@@ -2,58 +2,66 @@
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models, _
from odoo import _, fields, models
from odoo.exceptions import UserError
class AccountGroupGenerate(models.TransientModel):
_name = 'account.group.generate'
_description = 'Generate Account Groups'
_name = "account.group.generate"
_description = "Generate Account Groups"
name_prefix = fields.Char(string='Prefix', required=True, default='Comptes')
name_prefix = fields.Char(string="Prefix", required=True, default="Comptes")
level = fields.Integer(default=2, required=True)
def run(self):
if self.level < 1:
raise UserError(_("The level must be >= 1."))
ago = self.env['account.group']
aao = self.env['account.account']
ago = self.env["account.group"]
aao = self.env["account.account"]
company = self.env.company
groups = ago.search([('company_id', '=', company.id)])
groups = ago.search([("company_id", "=", company.id)])
if groups:
raise UserError(_(
"%d account groups already exists in company '%s'. This wizard is "
"designed to generate account groups from scratch.")
% (len(groups), company.display_name))
accounts = aao.search([('company_id', '=', company.id)])
struct = {'childs': {}}
raise UserError(
_(
"%d account groups already exists in company '%s'. This wizard is "
"designed to generate account groups from scratch."
)
% (len(groups), company.display_name)
)
accounts = aao.search([("company_id", "=", company.id)])
struct = {"childs": {}}
for account in accounts:
if len(account.code) <= self.level:
raise UserError(_(
"The code of account '%s' is %d caracters. "
"It cannot be inferior to level (%d).")
% (account.display_name, len(account.code), self.level))
raise UserError(
_(
"The code of account '%s' is %d caracters. "
"It cannot be inferior to level (%d)."
)
% (account.display_name, len(account.code), self.level)
)
n = 1
parent = struct
gparent = False
while n <= self.level:
group_code = account.code[:n]
if group_code not in parent['childs']:
new_group = ago.create({
'name': '%s %s' % (self.name_prefix or '', group_code),
'code_prefix_start': group_code,
'parent_id': gparent and gparent.id or False,
'company_id': company.id,
})
parent['childs'][group_code] = {'obj': new_group, 'childs': {}}
parent = parent['childs'][group_code]
gparent = parent['obj']
if group_code not in parent["childs"]:
new_group = ago.create(
{
"name": "%s %s" % (self.name_prefix or "", group_code),
"code_prefix_start": group_code,
"parent_id": gparent and gparent.id or False,
"company_id": company.id,
}
)
parent["childs"][group_code] = {"obj": new_group, "childs": {}}
parent = parent["childs"][group_code]
gparent = parent["obj"]
n += 1
account.write({'group_id': gparent.id})
account.write({"group_id": gparent.id})
action = {
'type': 'ir.actions.act_window',
'name': _('Account Groups'),
'view_mode': 'tree,form',
'res_model': 'account.group',
}
"type": "ir.actions.act_window",
"name": _("Account Groups"),
"view_mode": "tree,form",
"res_model": "account.group",
}
return action

View File

@@ -1,27 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2020 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="account_group_generate_form" model="ir.ui.view">
<field name="name">account.group.generate.form</field>
<field name="model">account.group.generate</field>
<field name="arch" type="xml">
<field name="arch" type="xml">
<form string="Generate account groups">
<p>
This wizard is designed to auto-generate account groups from the chart of account.
</p>
<group name="main">
<field name="name_prefix"/>
<field name="level"/>
<field name="name_prefix" />
<field name="level" />
</group>
<footer>
<button type="object" name="run" string="Generate" class="btn-primary"/>
<button special="cancel" string="Cancel"/>
<button
type="object"
name="run"
string="Generate"
class="btn-primary"
/>
<button special="cancel" string="Cancel" />
</footer>
</form>
</field>
@@ -34,9 +38,11 @@
<field name="target">new</field>
</record>
<menuitem id="account_group_generate_menu"
<menuitem
id="account_group_generate_menu"
action="account_group_generate_action"
parent="account.account_account_menu"
sequence="51"/>
sequence="51"
/>
</odoo>

View File

@@ -2,23 +2,29 @@
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
import logging
from odoo import models
logger = logging.getLogger(__name__)
class AccountInvoiceMarkSent(models.TransientModel):
_name = 'account.invoice.mark.sent'
_description = 'Mark invoices as sent'
_name = "account.invoice.mark.sent"
_description = "Mark invoices as sent"
def run(self):
assert self.env.context.get('active_model') == 'account.move',\
'Source model must be invoices'
assert self.env.context.get('active_ids'), 'No invoices selected'
invoices = self.env['account.move'].search([
('id', 'in', self.env.context.get('active_ids')),
('move_type', 'in', ('out_invoice', 'out_refund')),
('state', '=', 'posted')])
invoices.write({'is_move_sent': True})
logger.info('Marking invoices with ID %s as sent', invoices.ids)
assert (
self.env.context.get("active_model") == "account.move"
), "Source model must be invoices"
assert self.env.context.get("active_ids"), "No invoices selected"
invoices = self.env["account.move"].search(
[
("id", "in", self.env.context.get("active_ids")),
("move_type", "in", ("out_invoice", "out_refund")),
("state", "=", "posted"),
]
)
invoices.write({"is_move_sent": True})
logger.info("Marking invoices with ID %s as sent", invoices.ids)
return

View File

@@ -1,23 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2017-2020 Akretion France
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="account_invoice_mark_sent_form" model="ir.ui.view">
<field name="name">account.invoice.mark.sent.form</field>
<field name="model">account.invoice.mark.sent</field>
<field name="arch" type="xml">
<field name="arch" type="xml">
<form string="Mark invoices as sent">
<p>
This wizard will mark as <i>sent</i> all the selected invoices in open or paid state.
This wizard will mark as <i
>sent</i> all the selected invoices in open or paid state.
</p>
<footer>
<button type="object" name="run" string="Mark as Sent" class="btn-primary"/>
<button special="cancel" string="Cancel"/>
<button
type="object"
name="run"
string="Mark as Sent"
class="btn-primary"
/>
<button special="cancel" string="Cancel" />
</footer>
</form>
</field>

View File

@@ -2,20 +2,21 @@
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models
class AccountMoveReversal(models.TransientModel):
_inherit = 'account.move.reversal'
_inherit = "account.move.reversal"
@api.model
def _default_date(self):
date_dt = None
if (
self._context.get('active_model') == 'account.move' and
self._context.get('active_id')):
move = self.env['account.move'].browse(self._context['active_id'])
if self._context.get("active_model") == "account.move" and self._context.get(
"active_id"
):
move = self.env["account.move"].browse(self._context["active_id"])
date_dt = move.date + relativedelta(days=1)
return date_dt

View File

@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2021 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<!-- When you change the date, it resets the amount via the onchange
So, in the view, the date should be BEFORE the amount -->
<record id="view_account_payment_register_form" model="ir.ui.view">
<field name="model">account.payment.register</field>
<field name="inherit_id" ref="account.view_account_payment_register_form"/>
<field name="inherit_id" ref="account.view_account_payment_register_form" />
<field name="arch" type="xml">
<label for="amount" position="before">
<field name="payment_date" position="move"/>
<field name="payment_date" position="move" />
</label>
</field>
</record>

View File

@@ -6,7 +6,8 @@ from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
_inherit = "res.config.settings"
transfer_account_id = fields.Many2one(
related='company_id.transfer_account_id', readonly=False)
related="company_id.transfer_account_id", readonly=False
)