mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-23 17:22:00 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -6,186 +6,481 @@ from dateutil.relativedelta import relativedelta
|
|||
|
||||
from odoo import api, fields, models, Command
|
||||
from odoo.tools.misc import file_open, formatLang
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AccountChartTemplate(models.Model):
|
||||
class AccountChartTemplate(models.AbstractModel):
|
||||
_inherit = "account.chart.template"
|
||||
|
||||
@api.model
|
||||
def _get_demo_data(self):
|
||||
def _get_demo_data(self, company=False):
|
||||
"""Generate the demo data related to accounting."""
|
||||
# This is a generator because data created here might be referenced by xml_id to data
|
||||
# created later but defined in this same function.
|
||||
yield self._get_demo_data_move()
|
||||
yield self._get_demo_data_statement()
|
||||
yield self._get_demo_data_transactions()
|
||||
yield self._get_demo_data_reconcile_model()
|
||||
yield self._get_demo_data_attachment()
|
||||
yield self._get_demo_data_mail_message()
|
||||
yield self._get_demo_data_mail_activity()
|
||||
return {
|
||||
**self._get_demo_data_products(company),
|
||||
'account.move': self._get_demo_data_move(company),
|
||||
'account.bank.statement': self._get_demo_data_statement(company),
|
||||
'account.bank.statement.line': self._get_demo_data_transactions(company),
|
||||
'account.reconcile.model': self._get_demo_data_reconcile_model(company),
|
||||
'ir.attachment': self._get_demo_data_attachment(company),
|
||||
'mail.message': self._get_demo_data_mail_message(company),
|
||||
'mail.activity': self._get_demo_data_mail_activity(company),
|
||||
'product.product': self._get_demo_data_product(),
|
||||
'res.partner.bank': self._get_demo_data_bank(company),
|
||||
'res.partner': self._get_demo_data_partner(),
|
||||
'res.users': self._get_demo_data_user(),
|
||||
'account.journal': self._get_demo_data_journal(company),
|
||||
}
|
||||
|
||||
def _get_demo_exception_product_template_xml_ids(self):
|
||||
""" Return demo product template xml ids to not put taxes on"""
|
||||
return []
|
||||
|
||||
def _get_demo_exception_product_variant_xml_ids(self):
|
||||
""" Return demo product variant xml ids to not put taxes on"""
|
||||
return ['product.office_combo']
|
||||
|
||||
def _get_demo_data_products(self, company):
|
||||
# Only needed for the first company
|
||||
if company != self.env.ref('base.main_company', raise_if_not_found=False):
|
||||
return {}
|
||||
|
||||
taxes = {}
|
||||
if company.account_sale_tax_id:
|
||||
taxes.update({'taxes_id': [Command.link(company.account_sale_tax_id.id)]})
|
||||
if company.account_purchase_tax_id:
|
||||
taxes.update({'supplier_taxes_id': [Command.link(company.account_purchase_tax_id.id)]})
|
||||
if not taxes:
|
||||
return {}
|
||||
IMD = self.env['ir.model.data'].sudo()
|
||||
product_templates = sorted(
|
||||
set(IMD.search([('model', '=', 'product.template')]).mapped('complete_name'))
|
||||
- set(self._get_demo_exception_product_template_xml_ids())
|
||||
)
|
||||
product_variants = sorted(
|
||||
set(IMD.search([('model', '=', 'product.product')]).mapped('complete_name'))
|
||||
- set(self._get_demo_exception_product_variant_xml_ids())
|
||||
)
|
||||
return {
|
||||
'product.template': {d: taxes for d in product_templates},
|
||||
'product.product': {d: taxes for d in product_variants},
|
||||
}
|
||||
|
||||
def _post_load_demo_data(self, company=False):
|
||||
invoices = (
|
||||
self.ref('demo_invoice_1')
|
||||
+ self.ref('demo_invoice_2')
|
||||
+ self.ref('demo_invoice_3')
|
||||
+ self.ref('demo_invoice_followup')
|
||||
+ self.ref('demo_invoice_5')
|
||||
+ self.ref('demo_invoice_6')
|
||||
+ self.ref('demo_invoice_7')
|
||||
+ self.ref('demo_invoice_8')
|
||||
+ self.ref('demo_invoice_equipment_purchase')
|
||||
+ self.ref('demo_invoice_9')
|
||||
+ self.ref('demo_invoice_10')
|
||||
+ self.ref('demo_move_auto_reconcile_1')
|
||||
+ self.ref('demo_move_auto_reconcile_2')
|
||||
+ self.ref('demo_move_auto_reconcile_3')
|
||||
+ self.ref('demo_move_auto_reconcile_4')
|
||||
+ self.ref('demo_move_auto_reconcile_5')
|
||||
+ self.ref('demo_move_auto_reconcile_6')
|
||||
+ self.ref('demo_move_auto_reconcile_7')
|
||||
)
|
||||
|
||||
# the invoice_extract acts like a placeholder for the OCR to be ran and doesn't contain
|
||||
# any lines yet
|
||||
for move in invoices:
|
||||
try:
|
||||
move.action_post()
|
||||
except (UserError, ValidationError):
|
||||
_logger.exception('Error while posting demo data')
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_move(self):
|
||||
cid = self.env.company.id
|
||||
ref = self.env.ref
|
||||
return ('account.move', {
|
||||
f'{cid}_demo_invoice_1': {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': ref('base.res_partner_12').id,
|
||||
'invoice_user_id': ref('base.user_demo').id,
|
||||
'invoice_payment_term_id': ref('account.account_payment_term_end_following_month').id,
|
||||
'invoice_date': time.strftime('%Y-%m-01'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': ref('product.consu_delivery_02').id, 'quantity': 5}),
|
||||
Command.create({'product_id': ref('product.consu_delivery_03').id, 'quantity': 5}),
|
||||
],
|
||||
def _get_demo_data_bank(self, company=False):
|
||||
if company.root_id.partner_id.bank_ids:
|
||||
return {}
|
||||
return {
|
||||
'demo_bank_1': {
|
||||
'acc_number': f'BANK{company.id}34567890',
|
||||
'partner_id': company.root_id.partner_id.id,
|
||||
'journal_id': 'bank',
|
||||
'allow_out_payment': True,
|
||||
},
|
||||
f'{cid}_demo_invoice_2': {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': ref('base.res_partner_2').id,
|
||||
'invoice_user_id': False,
|
||||
'invoice_date': time.strftime('%Y-%m-08'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': ref('product.consu_delivery_03').id, 'quantity': 5}),
|
||||
Command.create({'product_id': ref('product.consu_delivery_01').id, 'quantity': 20}),
|
||||
],
|
||||
},
|
||||
f'{cid}_demo_invoice_3': {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': ref('base.res_partner_2').id,
|
||||
'invoice_user_id': False,
|
||||
'invoice_date': time.strftime('%Y-%m-08'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': ref('product.consu_delivery_01').id, 'quantity': 5}),
|
||||
Command.create({'product_id': ref('product.consu_delivery_03').id, 'quantity': 5}),
|
||||
],
|
||||
},
|
||||
f'{cid}_demo_invoice_followup': {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': ref('base.res_partner_2').id,
|
||||
'invoice_user_id': ref('base.user_demo').id,
|
||||
'invoice_payment_term_id': ref('account.account_payment_term_immediate').id,
|
||||
'invoice_date': (fields.Date.today() + timedelta(days=-15)).strftime('%Y-%m-%d'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': ref('product.consu_delivery_02').id, 'quantity': 5}),
|
||||
Command.create({'product_id': ref('product.consu_delivery_03').id, 'quantity': 5}),
|
||||
],
|
||||
},
|
||||
f'{cid}_demo_invoice_5': {
|
||||
'move_type': 'in_invoice',
|
||||
'partner_id': ref('base.res_partner_12').id,
|
||||
'invoice_payment_term_id': ref('account.account_payment_term_end_following_month').id,
|
||||
'invoice_date': time.strftime('%Y-%m-01'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': ref('product.product_delivery_01').id, 'price_unit': 10.0, 'quantity': 1}),
|
||||
Command.create({'product_id': ref('product.product_order_01').id, 'price_unit': 4.0, 'quantity': 5}),
|
||||
],
|
||||
},
|
||||
f'{cid}_demo_invoice_extract': {
|
||||
'move_type': 'in_invoice',
|
||||
},
|
||||
f'{cid}_demo_invoice_equipment_purchase': {
|
||||
'move_type': 'in_invoice',
|
||||
'ref': 'INV/2018/0057',
|
||||
'partner_id': ref('base.res_partner_12').id,
|
||||
'invoice_user_id': False,
|
||||
'invoice_date': '2018-09-17',
|
||||
'invoice_line_ids': [
|
||||
Command.create({'name': 'Redeem Reference Number: PO02529', 'quantity': 1, 'price_unit': 541.10}),
|
||||
],
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_statement(self):
|
||||
cid = self.env.company.id
|
||||
ref = self.env.ref
|
||||
bnk_journal = self.env['account.journal'].search(
|
||||
domain=[('type', '=', 'bank'), ('company_id', '=', cid)],
|
||||
def _get_demo_data_partner(self):
|
||||
if self.env.ref('base.res_partner_2', raise_if_not_found=False):
|
||||
return {}
|
||||
return {
|
||||
'base.res_partner_2': {'name': 'Demo Partner 2'},
|
||||
'base.res_partner_3': {'name': 'Demo Partner 3'},
|
||||
'base.res_partner_4': {'name': 'Demo Partner 4'},
|
||||
'base.res_partner_5': {'name': 'Demo Partner 5'},
|
||||
'base.res_partner_6': {'name': 'Demo Partner 6'},
|
||||
'base.res_partner_12': {'name': 'Demo Partner 12'},
|
||||
'base.partner_demo': {'name': 'Marc Demo'},
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_user(self):
|
||||
if self.env.ref('base.user_demo', raise_if_not_found=False):
|
||||
return {}
|
||||
return {
|
||||
'base.user_demo': {'name': 'Marc Demo', 'login': 'demo'}
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_product(self):
|
||||
if self.env.ref('product.product_delivery_01', raise_if_not_found=False):
|
||||
return {}
|
||||
return {
|
||||
'product.product_delivery_01': {'name': 'product_delivery_01', 'type': 'consu'},
|
||||
'product.product_delivery_02': {'name': 'product_delivery_02', 'type': 'consu'},
|
||||
'product.consu_delivery_01': {'name': 'consu_delivery_01', 'type': 'consu'},
|
||||
'product.consu_delivery_02': {'name': 'consu_delivery_02', 'type': 'consu'},
|
||||
'product.consu_delivery_03': {'name': 'consu_delivery_03', 'type': 'consu'},
|
||||
'product.product_order_01': {'name': 'product_order_01', 'type': 'consu'},
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_journal(self, company=False):
|
||||
if company.partner_id.bank_ids:
|
||||
# if a bank is created in xml, link it to the journal
|
||||
return {
|
||||
'bank': {
|
||||
'bank_account_id': company.partner_id.bank_ids[0].id,
|
||||
}
|
||||
}
|
||||
return {}
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_move(self, company=False):
|
||||
one_month_ago = fields.Date.today() + relativedelta(months=-1)
|
||||
cid = company.id or self.env.company.id
|
||||
misc_journal = self.env['account.journal'].search(
|
||||
domain=[
|
||||
*self.env['account.journal']._check_company_domain(cid),
|
||||
('type', '=', 'general'),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
return ('account.bank.statement', {
|
||||
f'{cid}_demo_bank_statement_0': {
|
||||
'name': f'{bnk_journal.name} - {time.strftime("%Y")}-01-01/1',
|
||||
'balance_end_real': 6378.0,
|
||||
'balance_start': 0.0,
|
||||
bank_journal = self.env['account.journal'].search(
|
||||
domain=[
|
||||
*self.env['account.journal']._check_company_domain(cid),
|
||||
('type', '=', 'bank'),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
default_receivable = self.env.company.partner_id.with_company(company or self.env.company).property_account_receivable_id
|
||||
income_account = self.env['account.account'].with_company(company or self.env.company).search([
|
||||
*self.env['account.account']._check_company_domain(cid),
|
||||
('account_type', '=', 'income'),
|
||||
('id', '!=', (company or self.env.company).account_journal_early_pay_discount_gain_account_id.id)
|
||||
], limit=1)
|
||||
return {
|
||||
self.company_xmlid('demo_invoice_1'): {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': 'base.res_partner_12',
|
||||
'invoice_user_id': 'base.user_demo',
|
||||
'invoice_payment_term_id': 'account.account_payment_term_end_following_month',
|
||||
'invoice_date': time.strftime('%Y-%m-01'),
|
||||
'delivery_date': time.strftime('%Y-%m-01'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.consu_delivery_02', 'quantity': 5}),
|
||||
Command.create({'product_id': 'product.consu_delivery_03', 'quantity': 5}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_invoice_2'): {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': 'base.res_partner_2',
|
||||
'invoice_user_id': False,
|
||||
'invoice_date': (fields.Date.today() + timedelta(days=-2)).strftime('%Y-%m-%d'),
|
||||
'delivery_date': (fields.Date.today() + timedelta(days=-2)).strftime('%Y-%m-%d'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.consu_delivery_03', 'quantity': 5}),
|
||||
Command.create({'product_id': 'product.consu_delivery_01', 'quantity': 20}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_invoice_3'): {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': 'base.res_partner_2',
|
||||
'invoice_user_id': False,
|
||||
'invoice_date': (fields.Date.today() + timedelta(days=-3)).strftime('%Y-%m-%d'),
|
||||
'delivery_date': (fields.Date.today() + timedelta(days=-3)).strftime('%Y-%m-%d'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.consu_delivery_01', 'quantity': 5}),
|
||||
Command.create({'product_id': 'product.consu_delivery_03', 'quantity': 5}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_invoice_followup'): {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': 'base.res_partner_2',
|
||||
'invoice_user_id': 'base.user_demo',
|
||||
'invoice_payment_term_id': 'account.account_payment_term_immediate',
|
||||
'invoice_date': (fields.Date.today() + timedelta(days=-15)).strftime('%Y-%m-%d'),
|
||||
'delivery_date': (fields.Date.today() + timedelta(days=-15)).strftime('%Y-%m-%d'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.consu_delivery_02', 'quantity': 5}),
|
||||
Command.create({'product_id': 'product.consu_delivery_03', 'quantity': 5}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_invoice_5'): {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': 'base.res_partner_5',
|
||||
'invoice_user_id': 'base.user_demo',
|
||||
'invoice_payment_term_id': 'account.account_payment_term_end_following_month',
|
||||
'invoice_date': (fields.Date.today() + timedelta(days=-40)).strftime('%Y-%m-%d'),
|
||||
'delivery_date': (fields.Date.today() + timedelta(days=-40)).strftime('%Y-%m-%d'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.product_order_01', 'price_unit': 200, 'quantity': 10}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_invoice_6'): {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': 'base.res_partner_5',
|
||||
'invoice_user_id': 'base.user_demo',
|
||||
'invoice_payment_term_id': 'account.account_payment_term_end_following_month',
|
||||
'invoice_date': (fields.Date.today() + timedelta(days=-35)).strftime('%Y-%m-%d'),
|
||||
'delivery_date': (fields.Date.today() + timedelta(days=-35)).strftime('%Y-%m-%d'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.product_order_01', 'price_unit': 100.0, 'quantity': 10}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_invoice_7'): {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': 'base.res_partner_5',
|
||||
'invoice_user_id': 'base.user_demo',
|
||||
'invoice_payment_term_id': 'account.account_payment_term_end_following_month',
|
||||
'invoice_date': (fields.Date.today() + relativedelta(months=-1)).strftime('%Y-%m-%d'),
|
||||
'delivery_date': (fields.Date.today() + relativedelta(months=-1)).strftime('%Y-%m-%d'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.product_order_01', 'price_unit': 275, 'quantity': 1}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_invoice_8'): {
|
||||
'move_type': 'in_invoice',
|
||||
'partner_id': 'base.res_partner_4',
|
||||
'invoice_payment_term_id': 'account.account_payment_term_end_following_month',
|
||||
'invoice_date': time.strftime('%Y-%m-01'),
|
||||
'delivery_date': time.strftime('%Y-%m-01'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.product_order_01', 'price_unit': 10.0, 'quantity': 1}),
|
||||
Command.create({'product_id': 'product.product_delivery_01', 'price_unit': 4, 'quantity': 5}),
|
||||
],
|
||||
'message_main_attachment_id': 'ir_attachment_in_invoice_1',
|
||||
},
|
||||
self.company_xmlid('demo_invoice_equipment_purchase'): {
|
||||
'move_type': 'in_invoice',
|
||||
'ref': f'INV/{(fields.Date.today() + timedelta(days=-20)).year}/0057',
|
||||
'partner_id': 'base.res_partner_3',
|
||||
'invoice_user_id': False,
|
||||
'invoice_date': (fields.Date.today() + timedelta(days=-20)).strftime("%Y-%m-%d"),
|
||||
'delivery_date': (fields.Date.today() + timedelta(days=-20)).strftime("%Y-%m-%d"),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'name': 'Redeem Reference Number: PO02529', 'quantity': 1, 'price_unit': 622.27}),
|
||||
],
|
||||
'message_main_attachment_id': 'ir_attachment_in_invoice_2',
|
||||
},
|
||||
self.company_xmlid('demo_invoice_9'): {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': 'base.res_partner_6',
|
||||
'invoice_user_id': False,
|
||||
'invoice_date': time.strftime('%Y-%m-%d'),
|
||||
'delivery_date': time.strftime('%Y-%m-%d'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.product_delivery_02', 'price_unit': 50.00, 'quantity': 15}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_invoice_10'): {
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': 'base.res_partner_5',
|
||||
'invoice_user_id': False,
|
||||
'invoice_date': (fields.Date.today() + timedelta(days=-5)).strftime('%Y-%m-%d'),
|
||||
'delivery_date': (fields.Date.today() + timedelta(days=-5)).strftime('%Y-%m-%d'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.consu_delivery_03', 'price_unit': 1799, 'quantity': 1}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_move_auto_reconcile_1'): {
|
||||
'move_type': 'out_refund',
|
||||
'partner_id': 'base.res_partner_12',
|
||||
'invoice_date': one_month_ago.strftime("%Y-%m-02"),
|
||||
'delivery_date': one_month_ago.strftime("%Y-%m-02"),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.consu_delivery_03', 'quantity': 5}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_move_auto_reconcile_2'): {
|
||||
'move_type': 'out_refund',
|
||||
'partner_id': 'base.res_partner_12',
|
||||
'invoice_date': one_month_ago.strftime("%Y-%m-03"),
|
||||
'delivery_date': one_month_ago.strftime("%Y-%m-03"),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.consu_delivery_02', 'quantity': 5}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_move_auto_reconcile_3'): {
|
||||
'move_type': 'in_refund',
|
||||
'partner_id': 'base.res_partner_4',
|
||||
'invoice_date': time.strftime('%Y-%m-01'),
|
||||
'delivery_date': time.strftime('%Y-%m-01'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.product_delivery_01', 'price_unit': 10.0, 'quantity': 1}),
|
||||
Command.create({'product_id': 'product.product_order_01', 'price_unit': 4.0, 'quantity': 5}),
|
||||
],
|
||||
'message_main_attachment_id': 'ir_attachment_in_invoice_1',
|
||||
},
|
||||
self.company_xmlid('demo_move_auto_reconcile_4'): {
|
||||
'move_type': 'out_refund',
|
||||
'partner_id': 'base.res_partner_2',
|
||||
'invoice_date': (fields.Date.today() + timedelta(days=-10)).strftime('%Y-%m-%d'),
|
||||
'delivery_date': (fields.Date.today() + timedelta(days=-10)).strftime('%Y-%m-%d'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.consu_delivery_02', 'quantity': 5}),
|
||||
Command.create({'product_id': 'product.consu_delivery_03', 'quantity': 5}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_move_auto_reconcile_5'): {
|
||||
'move_type': 'out_refund',
|
||||
'partner_id': 'base.res_partner_2',
|
||||
'invoice_date': (fields.Date.today() + timedelta(days=-2)).strftime('%Y-%m-%d'),
|
||||
'delivery_date': (fields.Date.today() + timedelta(days=-2)).strftime('%Y-%m-%d'),
|
||||
'invoice_line_ids': [
|
||||
Command.create({'product_id': 'product.consu_delivery_01', 'quantity': 5}),
|
||||
Command.create({'product_id': 'product.consu_delivery_03', 'quantity': 5}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_move_auto_reconcile_6'): {
|
||||
'move_type': 'entry',
|
||||
'partner_id': 'base.res_partner_2',
|
||||
'date': (fields.Date.today() + timedelta(days=-20)).strftime('%Y-%m-%d'),
|
||||
'journal_id': misc_journal.id,
|
||||
'line_ids': [
|
||||
Command.create({'debit': 0.0, 'credit': 2500.0, 'account_id': default_receivable.id}),
|
||||
Command.create({'debit': 2500.0, 'credit': 0.0, 'account_id': bank_journal.default_account_id.id}),
|
||||
],
|
||||
},
|
||||
self.company_xmlid('demo_move_auto_reconcile_7'): {
|
||||
'move_type': 'entry',
|
||||
'partner_id': 'base.res_partner_2',
|
||||
'date': (fields.Date.today() + timedelta(days=-20)).strftime('%Y-%m-%d'),
|
||||
'journal_id': misc_journal.id,
|
||||
'line_ids': [
|
||||
Command.create({'debit': 2500.0, 'credit': 0.0, 'account_id': default_receivable.id}),
|
||||
Command.create({'debit': 0.0, 'credit': 2500.0, 'account_id': income_account.id}),
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_statement(self, company=False):
|
||||
cid = company.id or self.env.company.id
|
||||
bnk_journal = self.env['account.journal'].search(
|
||||
domain=[
|
||||
*self.env['account.journal']._check_company_domain(cid),
|
||||
('type', '=', 'bank'),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
return {
|
||||
'demo_bank_statement_1': {
|
||||
'name': "Opening Statement: First Synchronization",
|
||||
'balance_end_real': 4253.0,
|
||||
'balance_start': 5103.0,
|
||||
'attachment_ids': [Command.set(['ir_attachment_bank_statement_1'])],
|
||||
'line_ids': [
|
||||
Command.create({
|
||||
'journal_id': bnk_journal.id,
|
||||
'payment_ref': 'Initial balance',
|
||||
'amount': 5103.0,
|
||||
'date': time.strftime('%Y-01-01'),
|
||||
}),
|
||||
Command.create({
|
||||
'journal_id': bnk_journal.id,
|
||||
'payment_ref': time.strftime('INV/%Y/00002 and INV/%Y/00003'),
|
||||
'amount': 1275.0,
|
||||
'date': time.strftime('%Y-01-01'),
|
||||
'partner_id': ref('base.res_partner_12').id
|
||||
'payment_ref': 'Office rent',
|
||||
'amount': -850.0,
|
||||
'date': (fields.Date.today() + relativedelta(months=-2)).strftime('%Y-%m-%d'),
|
||||
}),
|
||||
]
|
||||
},
|
||||
})
|
||||
'demo_bank_statement_2': {
|
||||
'name': f'{bnk_journal.name} - {(fields.Date.today() + relativedelta(months=-1)).strftime("%Y-%m-%d")}',
|
||||
'balance_end_real': 6678.0,
|
||||
'balance_start': 4253.0,
|
||||
'attachment_ids': [Command.set(['ir_attachment_bank_statement_2'])],
|
||||
'line_ids': [
|
||||
Command.create({
|
||||
'journal_id': bnk_journal.id,
|
||||
'payment_ref': 'Office rent',
|
||||
'amount': -850.0,
|
||||
'date': (fields.Date.today() + relativedelta(months=-1)).strftime('%Y-%m-%d'),
|
||||
}),
|
||||
Command.create({
|
||||
'journal_id': bnk_journal.id,
|
||||
'payment_ref': time.strftime('INV/%Y/00006 and INV/%Y/00007'),
|
||||
'amount': 1275.0,
|
||||
'date': (fields.Date.today() + relativedelta(months=-1)).strftime('%Y-%m-%d'),
|
||||
'partner_name': 'Open Wood Inc.',
|
||||
}),
|
||||
Command.create({
|
||||
'journal_id': bnk_journal.id,
|
||||
'payment_ref': 'Payment of your invoice #5',
|
||||
'amount': 2000.0,
|
||||
'date': (fields.Date.today() + timedelta(days=-40)).strftime('%Y-%m-%d'),
|
||||
'partner_name': 'Open Wood Inc.',
|
||||
}),
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_transactions(self):
|
||||
cid = self.env.company.id
|
||||
ref = self.env.ref
|
||||
def _get_demo_data_transactions(self, company=False):
|
||||
cid = company.id or self.env.company.id
|
||||
bnk_journal = self.env['account.journal'].search(
|
||||
domain=[('type', '=', 'bank'), ('company_id', '=', cid)],
|
||||
domain=[
|
||||
*self.env['account.journal']._check_company_domain(cid),
|
||||
('type', '=', 'bank'),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
return ('account.bank.statement.line', {
|
||||
f'{cid}_demo_bank_statement_line_0': {
|
||||
return {
|
||||
'demo_bank_statement_line_0': {
|
||||
'journal_id': bnk_journal.id,
|
||||
'payment_ref': 'Bank Fees',
|
||||
'amount': -32.58,
|
||||
'date': time.strftime('%Y-01-01'),
|
||||
'payment_ref': 'BILL/2024/01/0001',
|
||||
'amount': -622.27,
|
||||
'partner_id': 'base.res_partner_3',
|
||||
},
|
||||
f'{cid}_demo_bank_statement_line_1': {
|
||||
'demo_bank_statement_line_1': {
|
||||
'journal_id': bnk_journal.id,
|
||||
'payment_ref': 'Prepayment',
|
||||
'amount': 650,
|
||||
'date': time.strftime('%Y-01-01'),
|
||||
'partner_id': ref('base.res_partner_12').id
|
||||
'payment_ref': 'Office rent',
|
||||
'amount': -850.0,
|
||||
},
|
||||
f'{cid}_demo_bank_statement_line_2': {
|
||||
'demo_bank_statement_line_2': {
|
||||
'journal_id': bnk_journal.id,
|
||||
'payment_ref': time.strftime(f'First {formatLang(self.env, 2000, currency_obj=self.env.company.currency_id)} of invoice %Y/00001'),
|
||||
'amount': 2000,
|
||||
'date': time.strftime('%Y-01-01'),
|
||||
'partner_id': ref('base.res_partner_12').id
|
||||
'payment_ref': 'Prepayment for invoice #9',
|
||||
'amount': 650.0,
|
||||
'partner_name': 'Open Wood Inc.',
|
||||
},
|
||||
f'{cid}_demo_bank_statement_line_3': {
|
||||
'demo_bank_statement_line_3': {
|
||||
'journal_id': bnk_journal.id,
|
||||
'payment_ref': 'Last Year Interests',
|
||||
'amount': 102.78,
|
||||
'date': time.strftime('%Y-01-01'),
|
||||
},
|
||||
f'{cid}_demo_bank_statement_line_4': {
|
||||
'demo_bank_statement_line_4': {
|
||||
'journal_id': bnk_journal.id,
|
||||
'payment_ref': time.strftime('INV/%Y/00002'),
|
||||
'amount': 750,
|
||||
'date': time.strftime('%Y-01-01'),
|
||||
'partner_id': ref('base.res_partner_2').id
|
||||
'payment_ref': time.strftime('INV/%Y/00008'),
|
||||
'amount': 738.75,
|
||||
'partner_id': 'base.res_partner_6',
|
||||
},
|
||||
f'{cid}_demo_bank_statement_line_5': {
|
||||
'demo_bank_statement_line_5': {
|
||||
'journal_id': bnk_journal.id,
|
||||
'payment_ref': f'R:9772938 10/07 AX 9415116318 T:5 BRT: {formatLang(self.env, 100.0, digits=2)} C/ croip',
|
||||
'amount': 96.67,
|
||||
'date': time.strftime('%Y-01-01'),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_reconcile_model(self):
|
||||
cid = self.env.company.id
|
||||
return ('account.reconcile.model', {
|
||||
f'{cid}_reconcile_from_label': {
|
||||
def _get_demo_data_reconcile_model(self, company=False):
|
||||
return {
|
||||
'reconcile_from_label': {
|
||||
'name': 'Line with Bank Fees',
|
||||
'rule_type': 'writeoff_suggestion',
|
||||
'match_label': 'contains',
|
||||
'match_label_param': 'BRT',
|
||||
'line_ids': [
|
||||
|
|
@ -202,8 +497,8 @@ class AccountChartTemplate(models.Model):
|
|||
Command.create({
|
||||
'label': 'Bank Fees',
|
||||
'account_id': self._get_demo_account(
|
||||
'cost_of_goods_sold',
|
||||
'expense_direct_cost',
|
||||
'expense_finance',
|
||||
'expense',
|
||||
self.env.company,
|
||||
).id,
|
||||
'amount_type': 'percentage',
|
||||
|
|
@ -211,132 +506,171 @@ class AccountChartTemplate(models.Model):
|
|||
}),
|
||||
]
|
||||
},
|
||||
})
|
||||
'owner_current_account_model': {
|
||||
'name': "Owner's Current Account",
|
||||
'line_ids': [
|
||||
Command.create({
|
||||
'label': "Owner's Current Account",
|
||||
'account_id': self._get_demo_account(
|
||||
'owner_current_account',
|
||||
'asset_receivable',
|
||||
self.env.company,
|
||||
).id,
|
||||
'amount_type': 'percentage',
|
||||
'amount_string': '100',
|
||||
}),
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_attachment(self):
|
||||
cid = self.env.company.id
|
||||
ref = self.env.ref
|
||||
return ('ir.attachment', {
|
||||
f'{cid}_ir_attachment_in_invoice_1': {
|
||||
def _get_demo_data_attachment(self, company=False):
|
||||
return {
|
||||
'ir_attachment_in_invoice_1': {
|
||||
'type': 'binary',
|
||||
'name': 'in_invoice_yourcompany_demo.pdf',
|
||||
'res_model': 'account.move',
|
||||
'res_id': ref(f'account.{cid}_demo_invoice_extract').id,
|
||||
'res_id': 'demo_invoice_8',
|
||||
'res_field': 'invoice_pdf_report_file',
|
||||
'raw': file_open(
|
||||
'account/static/demo/in_invoice_yourcompany_demo_1.pdf', 'rb'
|
||||
).read()
|
||||
},
|
||||
f'{cid}_ir_attachment_in_invoice_2': {
|
||||
'ir_attachment_in_invoice_2': {
|
||||
'type': 'binary',
|
||||
'name': 'in_invoice_yourcompany_demo.pdf',
|
||||
'res_model': 'account.move',
|
||||
'res_id': ref(f'account.{cid}_demo_invoice_equipment_purchase').id,
|
||||
'res_id': 'demo_invoice_equipment_purchase',
|
||||
'res_field': 'invoice_pdf_report_file',
|
||||
'raw': file_open(
|
||||
'account/static/demo/in_invoice_yourcompany_demo_2.pdf', 'rb'
|
||||
).read()
|
||||
},
|
||||
})
|
||||
'ir_attachment_bank_statement_1': {
|
||||
'type': 'binary',
|
||||
'name': 'bank_opening_statement.pdf',
|
||||
'res_model': 'account.bank.statement',
|
||||
'res_id': 'demo_bank_statement_1',
|
||||
'raw': file_open(
|
||||
'account/static/demo/bank_opening_statement.pdf', 'rb'
|
||||
).read()
|
||||
},
|
||||
'ir_attachment_bank_statement_2': {
|
||||
'type': 'binary',
|
||||
'name': 'bank_statement_one_month_old.pdf',
|
||||
'res_model': 'account.bank.statement',
|
||||
'res_id': 'demo_bank_statement_2',
|
||||
'raw': file_open(
|
||||
'account/static/demo/bank_statement_one_month_old.pdf', 'rb'
|
||||
).read()
|
||||
},
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_mail_message(self):
|
||||
cid = self.env.company.id
|
||||
ref = self.env.ref
|
||||
return ('mail.message', {
|
||||
f'{cid}_mail_message_in_invoice_1': {
|
||||
def _get_demo_data_mail_message(self, company=False):
|
||||
return {
|
||||
'mail_message_in_invoice_1': {
|
||||
'model': 'account.move',
|
||||
'res_id': ref(f'account.{cid}_demo_invoice_extract').id,
|
||||
'res_id': 'demo_invoice_8',
|
||||
'body': 'Vendor Bill attachment',
|
||||
'message_type': 'comment',
|
||||
'author_id': ref('base.partner_demo').id,
|
||||
'author_id': 'base.partner_demo',
|
||||
'attachment_ids': [Command.set([
|
||||
ref(f'account.{cid}_ir_attachment_in_invoice_1').id
|
||||
'ir_attachment_in_invoice_1',
|
||||
])]
|
||||
},
|
||||
f'{cid}_mail_message_in_invoice_2': {
|
||||
'mail_message_in_invoice_2': {
|
||||
'model': 'account.move',
|
||||
'res_id': ref(f'account.{cid}_demo_invoice_equipment_purchase').id,
|
||||
'res_id': 'demo_invoice_equipment_purchase',
|
||||
'body': 'Vendor Bill attachment',
|
||||
'message_type': 'comment',
|
||||
'author_id': ref('base.partner_demo').id,
|
||||
'author_id': 'base.partner_demo',
|
||||
'attachment_ids': [Command.set([
|
||||
ref(f'account.{cid}_ir_attachment_in_invoice_2').id
|
||||
'ir_attachment_in_invoice_2',
|
||||
])]
|
||||
},
|
||||
})
|
||||
'mail_message_bank_statement_1': {
|
||||
'model': 'account.bank.statement',
|
||||
'res_id': 'demo_bank_statement_1',
|
||||
'body': 'Bank Statement attachment',
|
||||
'message_type': 'comment',
|
||||
'author_id': 'base.partner_demo',
|
||||
'attachment_ids': [Command.set([
|
||||
'ir_attachment_bank_statement_1',
|
||||
])]
|
||||
},
|
||||
'mail_message_bank_statement_2': {
|
||||
'model': 'account.bank.statement',
|
||||
'res_id': 'demo_bank_statement_2',
|
||||
'body': 'Bank Statement attachment',
|
||||
'message_type': 'comment',
|
||||
'author_id': 'base.partner_demo',
|
||||
'attachment_ids': [Command.set([
|
||||
'ir_attachment_bank_statement_2',
|
||||
])]
|
||||
},
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_demo_data_mail_activity(self):
|
||||
cid = self.env.company.id
|
||||
ref = self.env.ref
|
||||
return ('mail.activity', {
|
||||
f'{cid}_invoice_activity_1': {
|
||||
'res_id': ref(f'account.{cid}_demo_invoice_3').id,
|
||||
'res_model_id': ref('account.model_account_move').id,
|
||||
'activity_type_id': ref('mail.mail_activity_data_todo').id,
|
||||
def _get_demo_data_mail_activity(self, company=False):
|
||||
return {
|
||||
'invoice_activity_1': {
|
||||
'res_id': 'demo_invoice_3',
|
||||
'res_model_id': 'account.model_account_move',
|
||||
'activity_type_id': 'mail.mail_activity_data_todo',
|
||||
'date_deadline': (fields.Datetime.today() + relativedelta(days=5)).strftime('%Y-%m-%d %H:%M'),
|
||||
'summary': 'Follow-up on payment',
|
||||
'create_uid': ref('base.user_admin').id,
|
||||
'user_id': ref('base.user_admin').id,
|
||||
'create_uid': 'base.user_admin',
|
||||
'user_id': 'base.user_admin',
|
||||
},
|
||||
f'{cid}_invoice_activity_2': {
|
||||
'res_id': ref(f'account.{cid}_demo_invoice_2').id,
|
||||
'res_model_id': ref('account.model_account_move').id,
|
||||
'activity_type_id': ref('mail.mail_activity_data_call').id,
|
||||
'invoice_activity_2': {
|
||||
'res_id': 'demo_invoice_2',
|
||||
'res_model_id': 'account.model_account_move',
|
||||
'activity_type_id': 'mail.mail_activity_data_call',
|
||||
'date_deadline': fields.Datetime.today().strftime('%Y-%m-%d %H:%M'),
|
||||
'create_uid': ref('base.user_admin').id,
|
||||
'user_id': ref('base.user_admin').id,
|
||||
'summary': 'Follow up on missed call',
|
||||
'create_uid': 'base.user_admin',
|
||||
'user_id': 'base.user_admin',
|
||||
},
|
||||
f'{cid}_invoice_activity_3': {
|
||||
'res_id': ref(f'account.{cid}_demo_invoice_1').id,
|
||||
'res_model_id': ref('account.model_account_move').id,
|
||||
'activity_type_id': ref('mail.mail_activity_data_todo').id,
|
||||
'invoice_activity_3': {
|
||||
'res_id': 'demo_invoice_1',
|
||||
'res_model_id': 'account.model_account_move',
|
||||
'activity_type_id': 'mail.mail_activity_data_todo',
|
||||
'date_deadline': (fields.Datetime.today() + relativedelta(days=5)).strftime('%Y-%m-%d %H:%M'),
|
||||
'summary': 'Include upsell',
|
||||
'create_uid': ref('base.user_admin').id,
|
||||
'user_id': ref('base.user_admin').id,
|
||||
'create_uid': 'base.user_admin',
|
||||
'user_id': 'base.user_admin',
|
||||
},
|
||||
f'{cid}_invoice_activity_4': {
|
||||
'res_id': ref(f'account.{cid}_demo_invoice_extract').id,
|
||||
'res_model_id': ref('account.model_account_move').id,
|
||||
'activity_type_id': ref('mail.mail_activity_data_todo').id,
|
||||
'invoice_activity_4': {
|
||||
'res_id': 'demo_invoice_8',
|
||||
'res_model_id': 'account.model_account_move',
|
||||
'activity_type_id': 'mail.mail_activity_data_todo',
|
||||
'date_deadline': (fields.Datetime.today() + relativedelta(days=5)).strftime('%Y-%m-%d %H:%M'),
|
||||
'summary': 'Update address',
|
||||
'create_uid': ref('base.user_admin').id,
|
||||
'user_id': ref('base.user_admin').id,
|
||||
'create_uid': 'base.user_admin',
|
||||
'user_id': 'base.user_admin',
|
||||
},
|
||||
})
|
||||
|
||||
@api.model
|
||||
def _post_create_demo_data(self, created):
|
||||
cid = self.env.company.id
|
||||
if created._name == 'account.move':
|
||||
# the invoice_extract acts like a placeholder for the OCR to be ran and doesn't contain
|
||||
# any lines yet
|
||||
for move in created - self.env.ref(f'account.{cid}_demo_invoice_extract'):
|
||||
try:
|
||||
move.action_post()
|
||||
except Exception:
|
||||
_logger.exception('Error while posting demo data')
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_demo_account(self, xml_id, account_type, company):
|
||||
"""Find the most appropriate account possible for demo data creation.
|
||||
|
||||
:param xml_id (str): the xml_id of the account template in the generic coa
|
||||
:param account_type (str): the full xml_id of the account type wanted
|
||||
:param company (Model<res.company>): the company for which we search the account
|
||||
:return (Model<account.account>): the most appropriate record found
|
||||
:param str xml_id: the xml_id of the account template in the generic coa
|
||||
:param str account_type: the full xml_id of the account type wanted
|
||||
:param company: the company for which we search the account
|
||||
:return: the most appropriate ``account.account`` record found
|
||||
"""
|
||||
return (
|
||||
self.env['account.account'].browse(self.env['ir.model.data'].sudo().search([
|
||||
('name', '=', '%d_%s' % (company.id, xml_id)),
|
||||
('model', '=', 'account.account'),
|
||||
('module', '=like', 'l10n%')
|
||||
], limit=1).res_id)
|
||||
or self.env['account.account'].search([
|
||||
or self.env['account.account'].with_company(company).search([
|
||||
*self.env['account.account']._check_company_domain(company),
|
||||
('account_type', '=', account_type),
|
||||
('company_id', '=', company.id)
|
||||
], limit=1)
|
||||
or self.env['account.account'].search([('company_id', '=', company.id)], limit=1)
|
||||
or self.env['account.account'].with_company(company).search([
|
||||
*self.env['account.account']._check_company_domain(company),
|
||||
], limit=1)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<record id="base.user_demo" model="res.users">
|
||||
<field name="group_ids" eval="[(3, ref('account.group_account_manager'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="base.default_user_group" model="res.groups">
|
||||
<field name="implied_ids" eval="[(4, ref('account.group_account_manager'))]"/>
|
||||
</record>
|
||||
</data>
|
||||
<data>
|
||||
|
||||
<!-- TAGS FOR RETRIEVING THE DEMO ACCOUNTS -->
|
||||
|
||||
<record id="demo_capital_account" model="account.account.tag">
|
||||
<field name="name">Demo Capital Account</field>
|
||||
</record>
|
||||
|
|
@ -19,6 +26,26 @@
|
|||
<record id="demo_office_furniture_account" model="account.account.tag">
|
||||
<field name="name">Office Furniture</field>
|
||||
</record>
|
||||
|
||||
<!-- Install the demo if demo installation is triggered manually after install without demo -->
|
||||
<function model="account.chart.template" name="_install_demo">
|
||||
<value model="res.company" search="[('chart_template', '!=', False)]"/>
|
||||
</function>
|
||||
|
||||
<function model="account.chart.template" name="try_loading">
|
||||
<value eval="[]"/>
|
||||
<value>generic_coa</value>
|
||||
<value model="res.company" search="[('partner_id.country_id.code', '=', False)]"/>
|
||||
<value name="install_demo" eval="True"/>
|
||||
</function>
|
||||
|
||||
<function model="account.chart.template" name="try_loading">
|
||||
<value eval="[]"/>
|
||||
<value>generic_coa</value>
|
||||
<value model="res.company" eval="obj().env.ref('base.main_company')"/>
|
||||
<value name="install_demo" eval="True"/>
|
||||
</function>
|
||||
|
||||
<!-- Payment Terms -->
|
||||
|
||||
<record id="account_payment_term_advance" model="account.payment.term">
|
||||
|
|
@ -26,12 +53,8 @@
|
|||
<field name="note">Payment terms: 30% Advance End of Following Month</field>
|
||||
<field name="line_ids" eval="[
|
||||
Command.clear(),
|
||||
Command.create({'value': 'percent', 'value_amount': 30.0, 'days': 0}),
|
||||
Command.create({'value': 'balance', 'value_amount': 0.0, 'months': 1, 'end_month': True})]"/>
|
||||
</record>
|
||||
|
||||
<record id="base.user_demo" model="res.users">
|
||||
<field name="groups_id" eval="[(4,ref('account.group_account_invoice'))]"/>
|
||||
Command.create({'value': 'percent', 'value_amount': 30.0, 'nb_days': 0}),
|
||||
Command.create({'value': 'percent', 'value_amount': 70.0, 'delay_type': 'days_after_end_of_next_month','nb_days': 0})]"/>
|
||||
</record>
|
||||
|
||||
<!-- Add Payment terms on some demo partners -->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue