[MIG] partner_statement: Migration to 14.0

pull/859/head
Rujia Liu 2021-03-30 12:00:34 +13:00 committed by mariadforgeflow
parent 2bbdb6ea88
commit 7ed231555c
10 changed files with 150 additions and 183 deletions

View File

@ -3,7 +3,7 @@
{
"name": "Partner Statement",
"version": "13.0.1.2.2",
"version": "14.0.1.0.0",
"category": "Accounting & Finance",
"summary": "OCA Financial Reports",
"author": "ForgeFlow, Odoo Community Association (OCA)",
@ -12,6 +12,7 @@
"depends": ["account"],
"external_dependencies": {"python": ["dateutil"]},
"data": [
"security/ir.model.access.csv",
"security/statement_security.xml",
"views/activity_statement.xml",
"views/outstanding_statement.xml",

View File

@ -23,13 +23,15 @@ class ActivityStatement(models.AbstractModel):
ELSE sum(l.debit)
END as debit,
CASE WHEN l.currency_id is not null AND l.amount_currency < 0.0
THEN sum(-l.amount_currency)
THEN sum(l.amount_currency * (-1))
ELSE sum(l.credit)
END as credit
FROM account_move_line l
JOIN account_account aa ON (aa.id = l.account_id)
JOIN account_account_type at ON (at.id = aa.user_type_id)
JOIN account_move m ON (l.move_id = m.id)
WHERE l.partner_id IN %(partners)s
AND l.account_internal_type = %(account_type)s
AND at.type = %(account_type)s
AND l.date < %(date_start)s AND not l.blocked
AND m.state IN ('posted')
GROUP BY l.partner_id, l.currency_id, l.amount_currency, l.company_id
@ -105,10 +107,12 @@ class ActivityStatement(models.AbstractModel):
ELSE l.date_maturity
END as date_maturity
FROM account_move_line l
JOIN account_account aa ON (aa.id = l.account_id)
JOIN account_account_type at ON (at.id = aa.user_type_id)
JOIN account_move m ON (l.move_id = m.id)
JOIN account_journal aj ON (l.journal_id = aj.id)
WHERE l.partner_id IN %(partners)s
AND l.account_internal_type = %(account_type)s
AND at.type = %(account_type)s
AND %(date_start)s <= l.date
AND l.date <= %(date_end)s
AND m.state IN ('posted')

View File

@ -16,76 +16,62 @@ class OutstandingStatement(models.AbstractModel):
return str(
self._cr.mogrify(
"""
SELECT l.id, m.name AS move_id, l.partner_id, l.date, l.name,
l.blocked, l.currency_id, l.company_id,
CASE WHEN l.ref IS NOT NULL THEN l.ref ELSE m.ref END as ref,
SELECT l.id, m.name AS move_id, l.partner_id, l.date, l.name,
l.blocked, l.currency_id, l.company_id,
CASE WHEN l.ref IS NOT NULL
THEN l.ref
ELSE m.ref
END as ref,
CASE WHEN (l.currency_id is not null AND l.amount_currency > 0.0)
THEN avg(l.amount_currency)
ELSE avg(l.debit)
END as debit,
CASE WHEN (l.currency_id is not null AND l.amount_currency < 0.0)
THEN avg(-l.amount_currency)
THEN avg(l.amount_currency * (-1))
ELSE avg(l.credit)
END as credit,
(abs(COALESCE(l.balance, 0.0)) + sum(
coalesce(pr.pr_sign, 0.0) * coalesce(pr.amount, 0.0))
) * sign(COALESCE(l.balance, 0.0)) AS open_amount,
(abs(COALESCE(l.amount_currency, 0.0)) + sum(
coalesce(pr.pr_sign, 0.0) * CASE
WHEN pr.currency_id IS NOT NULL AND pr.currency_id = l.currency_id
THEN coalesce(pr.amount_currency, 0.0)
WHEN cur.id IS NOT NULL AND ROUND(
abs(COALESCE(l.balance, 0.0)), cur.decimal_places) > 0.0
THEN ROUND(coalesce(pr.amount, 0.0) *
COALESCE(l.amount_currency, 0.0) / NULLIF(l.balance, 0.0),
cur.decimal_places)
ELSE ROUND(coalesce(pr.amount, 0.0) *
COALESCE((
SELECT r.rate FROM res_currency_rate r
JOIN account_move_line aml
ON pr.credit_move_id = aml.id
WHERE r.currency_id = l.currency_id
AND r.name <= aml.date
AND (r.company_id IS NULL
OR r.company_id = l.company_id)
ORDER BY r.company_id, r.name DESC LIMIT 1), 1.0),
cur.decimal_places)
END)
) * sign(COALESCE(l.amount_currency, 0.0)) AS open_amount_currency,
CASE WHEN l.balance > 0.0
THEN l.balance - sum(coalesce(pd.amount, 0.0))
ELSE l.balance + sum(coalesce(pc.amount, 0.0))
END AS open_amount,
CASE WHEN l.balance > 0.0
THEN l.amount_currency - sum(coalesce(pd.debit_amount_currency, 0.0))
ELSE l.amount_currency + sum(coalesce(pc.credit_amount_currency, 0.0))
END AS open_amount_currency,
CASE WHEN l.date_maturity is null
THEN l.date
ELSE l.date_maturity
END as date_maturity
FROM (
SELECT l.*, CASE
WHEN l.debit = 0.0 AND l.credit = 0.0 AND l.currency_id IS NOT NULL
AND ROUND(COALESCE(l.amount_currency, 0.0),
cur.decimal_places) > 0.0 THEN 1
WHEN l.debit = 0.0 AND l.credit = 0.0 AND l.currency_id IS NOT NULL
AND ROUND(COALESCE(l.amount_currency, 0.0),
cur.decimal_places) < 0.0 THEN -1
WHEN l.balance > 0.0 THEN 1 ELSE -1 END as sign
FROM account_move_line l
LEFT JOIN res_currency cur ON cur.id = l.currency_id
) l
JOIN account_move m ON l.move_id = m.id
LEFT JOIN res_currency cur ON cur.id = l.currency_id
LEFT JOIN LATERAL (SELECT pr.*,
CASE WHEN pr.credit_move_id = l.id THEN l.sign
ELSE -l.sign END AS pr_sign
FROM account_partial_reconcile pr
WHERE pr.max_date <= %(date_end)s AND (
(pr.debit_move_id = l.id) OR (pr.credit_move_id = l.id))
) as pr ON TRUE
WHERE l.partner_id IN %(partners)s
AND l.account_internal_type = %(account_type)s
AND (
(pr.id IS NOT NULL AND pr.max_date <= %(date_end)s) OR
(pr.id IS NULL)
) AND l.date <= %(date_end)s AND m.state IN ('posted')
GROUP BY l.id, l.partner_id, m.name, l.date, l.date_maturity, l.name,
CASE WHEN l.ref IS NOT NULL THEN l.ref ELSE m.ref END,
l.blocked, l.currency_id, l.balance, l.amount_currency, l.company_id
JOIN account_account aa ON (aa.id = l.account_id)
JOIN account_account_type at ON (at.id = aa.user_type_id)
JOIN account_move m ON (l.move_id = m.id)
LEFT JOIN (SELECT pr.*
FROM account_partial_reconcile pr
INNER JOIN account_move_line l2
ON pr.credit_move_id = l2.id
WHERE l2.date <= %(date_end)s
) as pd ON pd.debit_move_id = l.id
LEFT JOIN (SELECT pr.*
FROM account_partial_reconcile pr
INNER JOIN account_move_line l2
ON pr.debit_move_id = l2.id
WHERE l2.date <= %(date_end)s
) as pc ON pc.credit_move_id = l.id
WHERE l.partner_id IN %(partners)s AND at.type = %(account_type)s
AND (
(pd.id IS NOT NULL AND
pd.max_date <= %(date_end)s) OR
(pc.id IS NOT NULL AND
pc.max_date <= %(date_end)s) OR
(pd.id IS NULL AND pc.id IS NULL)
) AND l.date <= %(date_end)s AND m.state IN ('posted')
GROUP BY l.id, l.partner_id, m.name, l.date, l.date_maturity, l.name,
CASE WHEN l.ref IS NOT NULL
THEN l.ref
ELSE m.ref
END,
l.blocked, l.currency_id, l.balance, l.amount_currency, l.company_id
""",
locals(),
),
@ -121,9 +107,7 @@ class OutstandingStatement(models.AbstractModel):
Q2.open_amount
FROM Q2
JOIN res_company c ON (c.id = Q2.company_id)
JOIN res_currency cur ON cur.id = COALESCE(Q2.currency_id, c.currency_id)
WHERE c.id = %(company_id)s AND
round(Q2.open_amount, cur.decimal_places) != 0.0
WHERE c.id = %(company_id)s AND Q2.open_amount != 0.0
""",
locals(),
),

View File

@ -38,66 +38,47 @@ class ReportStatementCommon(models.AbstractModel):
return str(
self._cr.mogrify(
"""
SELECT l.partner_id, l.currency_id, l.company_id, l.move_id,
(abs(COALESCE(l.balance, 0.0)) + sum(
coalesce(pr.pr_sign, 0.0) * coalesce(pr.amount, 0.0))
) * sign(COALESCE(l.balance, 0.0)) AS open_due,
(abs(COALESCE(l.amount_currency, 0.0)) + sum(
coalesce(pr.pr_sign, 0.0) * CASE
WHEN pr.currency_id IS NOT NULL AND pr.currency_id = l.currency_id
THEN coalesce(pr.amount_currency, 0.0)
WHEN cur.id IS NOT NULL AND ROUND(
abs(COALESCE(l.balance, 0.0)), cur.decimal_places) > 0.0
THEN ROUND(coalesce(pr.amount, 0.0) *
COALESCE(l.amount_currency, 0.0) / NULLIF(l.balance, 0.0),
cur.decimal_places)
ELSE ROUND(coalesce(pr.amount, 0.0) *
COALESCE((
SELECT r.rate FROM res_currency_rate r
JOIN account_move_line aml
ON pr.credit_move_id = aml.id
WHERE r.currency_id = l.currency_id
AND r.name <= aml.date
AND (r.company_id IS NULL
OR r.company_id = l.company_id)
ORDER BY r.company_id, r.name DESC LIMIT 1), 1.0),
cur.decimal_places)
END)
) * sign(COALESCE(l.amount_currency, 0.0)) AS open_due_currency,
SELECT l.partner_id, l.currency_id, l.company_id, l.move_id,
CASE WHEN l.balance > 0.0
THEN l.balance - sum(coalesce(pd.amount, 0.0))
ELSE l.balance + sum(coalesce(pc.amount, 0.0))
END AS open_due,
CASE WHEN l.balance > 0.0
THEN l.amount_currency - sum(coalesce(pd.debit_amount_currency, 0.0))
ELSE l.amount_currency + sum(coalesce(pc.credit_amount_currency, 0.0))
END AS open_due_currency,
CASE WHEN l.date_maturity is null
THEN l.date
ELSE l.date_maturity
END as date_maturity
FROM (
SELECT l.*, CASE
WHEN l.debit = 0.0 AND l.credit = 0.0 AND l.currency_id IS NOT NULL
AND ROUND(COALESCE(l.amount_currency, 0.0),
cur.decimal_places) > 0.0 THEN 1
WHEN l.debit = 0.0 AND l.credit = 0.0 AND l.currency_id IS NOT NULL
AND ROUND(COALESCE(l.amount_currency, 0.0),
cur.decimal_places) < 0.0 THEN -1
WHEN l.balance > 0.0 THEN 1 ELSE -1 END as sign
END as date_maturity
FROM account_move_line l
LEFT JOIN res_currency cur ON cur.id = l.currency_id
) l
JOIN account_move m ON l.move_id = m.id
LEFT JOIN res_currency cur ON cur.id = l.currency_id
LEFT JOIN LATERAL (SELECT pr.*,
CASE WHEN pr.credit_move_id = l.id THEN l.sign
ELSE -l.sign END AS pr_sign
FROM account_partial_reconcile pr
WHERE pr.max_date <= %(date_end)s AND (
(pr.debit_move_id = l.id) OR (pr.credit_move_id = l.id))
) as pr ON TRUE
WHERE l.partner_id IN %(partners)s
AND l.account_internal_type = %(account_type)s
AND (
(pr.id IS NOT NULL AND pr.max_date <= %(date_end)s) OR
(pr.id IS NULL)
) AND l.date <= %(date_end)s AND not l.blocked
AND m.state IN ('posted')
GROUP BY l.partner_id, l.currency_id, l.date, l.date_maturity,
l.amount_currency, l.balance, l.move_id, l.company_id, l.id
JOIN account_move m ON (l.move_id = m.id)
JOIN account_account aa ON (aa.id = l.account_id)
JOIN account_account_type at ON (at.id = aa.user_type_id)
LEFT JOIN (SELECT pr.*
FROM account_partial_reconcile pr
INNER JOIN account_move_line l2
ON pr.credit_move_id = l2.id
WHERE l2.date <= %(date_end)s
) as pd ON pd.debit_move_id = l.id
LEFT JOIN (SELECT pr.*
FROM account_partial_reconcile pr
INNER JOIN account_move_line l2
ON pr.debit_move_id = l2.id
WHERE l2.date <= %(date_end)s
) as pc ON pc.credit_move_id = l.id
WHERE l.partner_id IN %(partners)s AND at.type = %(account_type)s
AND (
(pd.id IS NOT NULL AND
pd.max_date <= %(date_end)s) OR
(pc.id IS NOT NULL AND
pc.max_date <= %(date_end)s) OR
(pd.id IS NULL AND pc.id IS NULL)
) AND l.date <= %(date_end)s AND not l.blocked
AND m.state IN ('posted')
GROUP BY l.partner_id, l.currency_id, l.date, l.date_maturity,
l.amount_currency, l.balance, l.move_id,
l.company_id, l.id
""",
locals(),
),
@ -307,8 +288,8 @@ class ReportStatementCommon(models.AbstractModel):
)
@api.model
# flake8: noqa: C901
def _get_report_values(self, docids, data=None):
# flake8: noqa: C901
"""
@return: returns a dict of parameters to pass to qweb report.
the most important pair is {'data': res} which contains all

View File

@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_activity_statement_wizard,access_activity_statement_wizard,model_activity_statement_wizard,account.group_account_invoice,1,1,1,0
access_outstanding_statement_wizard,access_outstanding_statement_wizard,model_outstanding_statement_wizard,account.group_account_invoice,1,1,1,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_activity_statement_wizard access_activity_statement_wizard model_activity_statement_wizard account.group_account_invoice 1 1 1 0
3 access_outstanding_statement_wizard access_outstanding_statement_wizard model_outstanding_statement_wizard account.group_account_invoice 1 1 1 0

View File

@ -32,4 +32,4 @@ class TestResConfigSettings(TransactionCase):
self.user_obj._has_group("partner_statement.group_activity_statement")
)
res = self.env["ir.default"].get("activity.statement.wizard", "aging_type")
self.assertEquals(res, "months")
self.assertEqual(res, "months")

View File

@ -161,13 +161,11 @@
</t>
</t>
</template>
<report
id="action_print_activity_statement"
model="res.partner"
report_type="qweb-pdf"
menu="False"
string="Activity Statement"
name="partner_statement.activity_statement"
file="partner_statement.activity_statement"
/>
<record id="action_print_activity_statement" model="ir.actions.report">
<field name="name">Activity Statement</field>
<field name="model">res.partner</field>
<field name="report_name">partner_statement.activity_statement</field>
<field name="report_type">qweb-pdf</field>
<field name="report_file">partner_statement.activity_statement</field>
</record>
</odoo>

View File

@ -157,13 +157,11 @@
</t>
</t>
</template>
<report
id="action_print_outstanding_statement"
model="res.partner"
report_type="qweb-pdf"
menu="False"
string="Outstanding Statement"
name="partner_statement.outstanding_statement"
file="partner_statement.outstanding_statement"
/>
<record id="action_print_outstanding_statement" model="ir.actions.report">
<field name="name">Outstanding Statement</field>
<field name="model">res.partner</field>
<field name="report_name">partner_statement.outstanding_statement</field>
<field name="report_type">qweb-pdf</field>
<field name="report_file">partner_statement.outstanding_statement</field>
</record>
</odoo>

View File

@ -11,16 +11,10 @@ class StatementCommon(models.AbstractModel):
_name = "statement.common.wizard"
_description = "Statement Reports Common Wizard"
def _get_company(self):
return (
self.env["res.company"].browse(self.env.context.get("force_company"))
or self.env.company
)
name = fields.Char()
company_id = fields.Many2one(
comodel_name="res.company",
default=_get_company,
default=lambda self: self.env.company,
string="Company",
required=True,
)

View File

@ -3,24 +3,28 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<!-- wizard action on res.partner -->
<act_window
id="activity_statement_wizard_action"
name="Partner Activity Statement"
binding_model="res.partner"
res_model="activity.statement.wizard"
view_mode="form"
target="new"
groups="partner_statement.group_activity_statement"
/>
<act_window
id="outstanding_statement_wizard_action"
name="Partner Outstanding Statement"
binding_model="res.partner"
res_model="outstanding.statement.wizard"
view_mode="form"
target="new"
groups="partner_statement.group_outstanding_statement"
/>
<record id="activity_statement_wizard_action" model="ir.actions.act_window">
<field name="name">Partner Activity Statement</field>
<field name="binding_model_id" ref="base.model_res_partner" />
<field name="res_model">activity.statement.wizard</field>
<field name="view_mode">form</field>
<field
name="groups_id"
eval="[(4, ref('partner_statement.group_activity_statement'))]"
/>
<field name="target">new</field>
</record>
<record id="outstanding_statement_wizard_action" model="ir.actions.act_window">
<field name="name">Partner Outstanding Statement</field>
<field name="binding_model_id" ref="base.model_res_partner" />
<field name="res_model">outstanding.statement.wizard</field>
<field name="view_mode">form</field>
<field
name="groups_id"
eval="[(4, ref('partner_statement.group_outstanding_statement'))]"
/>
<field name="target">new</field>
</record>
<!-- wizard view -->
<record id="statement_common_view" model="ir.ui.view">
<field name="name">Statement Common Wizard View</field>
@ -28,11 +32,11 @@
<field name="arch" type="xml">
<form name="Report Options">
<div style="text-align:justify" name="info">
<label
string="Aging details can be shown in the report, expressed in aging
buckets, so the partner can review how much is open, due or overdue."
for=""
/>
<span
class="o_form_label"
>Aging details can be shown in the report, expressed in aging
buckets, so the partner can review how much is open, due or overdue.
</span>
</div>
<hr />
<group>
@ -86,14 +90,14 @@
<field name="inherit_id" ref="partner_statement.statement_common_view" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//div[@name='info']/label" position="before">
<label
string="The outstanding statement provides details of all partner's outstanding
<xpath expr="//div[@name='info']/span" position="before">
<span
class="o_form_label"
>The outstanding statement provides details of all partner's outstanding
receivables and payables up to a particular date. This includes all unpaid invoices, unclaimed
refunds and outstanding payments. The list is displayed in chronological order and is
split by currencies."
for=""
/>
split by currencies.
</span>
<br />
<br />
</xpath>
@ -105,15 +109,15 @@
<field name="inherit_id" ref="partner_statement.statement_common_view" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//div[@name='info']/label" position="before">
<label
string="The activity statement provides details of all activity on
<xpath expr="//div[@name='info']/span" position="before">
<span
class="o_form_label"
>The activity statement provides details of all activity on
a partner's receivables and payables between two selected dates. This includes all invoices,
refunds and payments. Any outstanding balance dated prior to the chosen statement
period will appear as a forward balance at the top of the statement. The list is
displayed in chronological order and is split by currencies."
for=""
/>
displayed in chronological order and is split by currencies.
</span>
<br />
<br />
</xpath>