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

View File

@ -23,13 +23,15 @@ class ActivityStatement(models.AbstractModel):
ELSE sum(l.debit) ELSE sum(l.debit)
END as debit, END as debit,
CASE WHEN l.currency_id is not null AND l.amount_currency < 0.0 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) ELSE sum(l.credit)
END as credit END as credit
FROM account_move_line l 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_move m ON (l.move_id = m.id)
WHERE l.partner_id IN %(partners)s 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 l.date < %(date_start)s AND not l.blocked
AND m.state IN ('posted') AND m.state IN ('posted')
GROUP BY l.partner_id, l.currency_id, l.amount_currency, l.company_id 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 ELSE l.date_maturity
END as date_maturity END as date_maturity
FROM account_move_line l 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_move m ON (l.move_id = m.id)
JOIN account_journal aj ON (l.journal_id = aj.id) JOIN account_journal aj ON (l.journal_id = aj.id)
WHERE l.partner_id IN %(partners)s 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 %(date_start)s <= l.date
AND l.date <= %(date_end)s AND l.date <= %(date_end)s
AND m.state IN ('posted') AND m.state IN ('posted')

View File

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

View File

@ -38,66 +38,47 @@ class ReportStatementCommon(models.AbstractModel):
return str( return str(
self._cr.mogrify( self._cr.mogrify(
""" """
SELECT l.partner_id, l.currency_id, l.company_id, l.move_id, SELECT l.partner_id, l.currency_id, l.company_id, l.move_id,
(abs(COALESCE(l.balance, 0.0)) + sum( CASE WHEN l.balance > 0.0
coalesce(pr.pr_sign, 0.0) * coalesce(pr.amount, 0.0)) THEN l.balance - sum(coalesce(pd.amount, 0.0))
) * sign(COALESCE(l.balance, 0.0)) AS open_due, ELSE l.balance + sum(coalesce(pc.amount, 0.0))
(abs(COALESCE(l.amount_currency, 0.0)) + sum( END AS open_due,
coalesce(pr.pr_sign, 0.0) * CASE CASE WHEN l.balance > 0.0
WHEN pr.currency_id IS NOT NULL AND pr.currency_id = l.currency_id THEN l.amount_currency - sum(coalesce(pd.debit_amount_currency, 0.0))
THEN coalesce(pr.amount_currency, 0.0) ELSE l.amount_currency + sum(coalesce(pc.credit_amount_currency, 0.0))
WHEN cur.id IS NOT NULL AND ROUND( END AS open_due_currency,
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,
CASE WHEN l.date_maturity is null CASE WHEN l.date_maturity is null
THEN l.date THEN l.date
ELSE l.date_maturity ELSE l.date_maturity
END as 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 FROM account_move_line l
LEFT JOIN res_currency cur ON cur.id = l.currency_id JOIN account_move m ON (l.move_id = m.id)
) l JOIN account_account aa ON (aa.id = l.account_id)
JOIN account_move m ON l.move_id = m.id JOIN account_account_type at ON (at.id = aa.user_type_id)
LEFT JOIN res_currency cur ON cur.id = l.currency_id LEFT JOIN (SELECT pr.*
LEFT JOIN LATERAL (SELECT pr.*, FROM account_partial_reconcile pr
CASE WHEN pr.credit_move_id = l.id THEN l.sign INNER JOIN account_move_line l2
ELSE -l.sign END AS pr_sign ON pr.credit_move_id = l2.id
FROM account_partial_reconcile pr WHERE l2.date <= %(date_end)s
WHERE pr.max_date <= %(date_end)s AND ( ) as pd ON pd.debit_move_id = l.id
(pr.debit_move_id = l.id) OR (pr.credit_move_id = l.id)) LEFT JOIN (SELECT pr.*
) as pr ON TRUE FROM account_partial_reconcile pr
WHERE l.partner_id IN %(partners)s INNER JOIN account_move_line l2
AND l.account_internal_type = %(account_type)s ON pr.debit_move_id = l2.id
AND ( WHERE l2.date <= %(date_end)s
(pr.id IS NOT NULL AND pr.max_date <= %(date_end)s) OR ) as pc ON pc.credit_move_id = l.id
(pr.id IS NULL) WHERE l.partner_id IN %(partners)s AND at.type = %(account_type)s
) AND l.date <= %(date_end)s AND not l.blocked AND (
AND m.state IN ('posted') (pd.id IS NOT NULL AND
GROUP BY l.partner_id, l.currency_id, l.date, l.date_maturity, pd.max_date <= %(date_end)s) OR
l.amount_currency, l.balance, l.move_id, l.company_id, l.id (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(), locals(),
), ),
@ -307,8 +288,8 @@ class ReportStatementCommon(models.AbstractModel):
) )
@api.model @api.model
# flake8: noqa: C901
def _get_report_values(self, docids, data=None): def _get_report_values(self, docids, data=None):
# flake8: noqa: C901
""" """
@return: returns a dict of parameters to pass to qweb report. @return: returns a dict of parameters to pass to qweb report.
the most important pair is {'data': res} which contains all 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") self.user_obj._has_group("partner_statement.group_activity_statement")
) )
res = self.env["ir.default"].get("activity.statement.wizard", "aging_type") 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>
</t> </t>
</template> </template>
<report <record id="action_print_activity_statement" model="ir.actions.report">
id="action_print_activity_statement" <field name="name">Activity Statement</field>
model="res.partner" <field name="model">res.partner</field>
report_type="qweb-pdf" <field name="report_name">partner_statement.activity_statement</field>
menu="False" <field name="report_type">qweb-pdf</field>
string="Activity Statement" <field name="report_file">partner_statement.activity_statement</field>
name="partner_statement.activity_statement" </record>
file="partner_statement.activity_statement"
/>
</odoo> </odoo>

View File

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

View File

@ -11,16 +11,10 @@ class StatementCommon(models.AbstractModel):
_name = "statement.common.wizard" _name = "statement.common.wizard"
_description = "Statement Reports 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() name = fields.Char()
company_id = fields.Many2one( company_id = fields.Many2one(
comodel_name="res.company", comodel_name="res.company",
default=_get_company, default=lambda self: self.env.company,
string="Company", string="Company",
required=True, required=True,
) )

View File

@ -3,24 +3,28 @@
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>
<!-- wizard action on res.partner --> <!-- wizard action on res.partner -->
<act_window <record id="activity_statement_wizard_action" model="ir.actions.act_window">
id="activity_statement_wizard_action" <field name="name">Partner Activity Statement</field>
name="Partner Activity Statement" <field name="binding_model_id" ref="base.model_res_partner" />
binding_model="res.partner" <field name="res_model">activity.statement.wizard</field>
res_model="activity.statement.wizard" <field name="view_mode">form</field>
view_mode="form" <field
target="new" name="groups_id"
groups="partner_statement.group_activity_statement" eval="[(4, ref('partner_statement.group_activity_statement'))]"
/> />
<act_window <field name="target">new</field>
id="outstanding_statement_wizard_action" </record>
name="Partner Outstanding Statement" <record id="outstanding_statement_wizard_action" model="ir.actions.act_window">
binding_model="res.partner" <field name="name">Partner Outstanding Statement</field>
res_model="outstanding.statement.wizard" <field name="binding_model_id" ref="base.model_res_partner" />
view_mode="form" <field name="res_model">outstanding.statement.wizard</field>
target="new" <field name="view_mode">form</field>
groups="partner_statement.group_outstanding_statement" <field
/> name="groups_id"
eval="[(4, ref('partner_statement.group_outstanding_statement'))]"
/>
<field name="target">new</field>
</record>
<!-- wizard view --> <!-- wizard view -->
<record id="statement_common_view" model="ir.ui.view"> <record id="statement_common_view" model="ir.ui.view">
<field name="name">Statement Common Wizard View</field> <field name="name">Statement Common Wizard View</field>
@ -28,11 +32,11 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<form name="Report Options"> <form name="Report Options">
<div style="text-align:justify" name="info"> <div style="text-align:justify" name="info">
<label <span
string="Aging details can be shown in the report, expressed in aging class="o_form_label"
buckets, so the partner can review how much is open, due or overdue." >Aging details can be shown in the report, expressed in aging
for="" buckets, so the partner can review how much is open, due or overdue.
/> </span>
</div> </div>
<hr /> <hr />
<group> <group>
@ -86,14 +90,14 @@
<field name="inherit_id" ref="partner_statement.statement_common_view" /> <field name="inherit_id" ref="partner_statement.statement_common_view" />
<field name="mode">primary</field> <field name="mode">primary</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//div[@name='info']/label" position="before"> <xpath expr="//div[@name='info']/span" position="before">
<label <span
string="The outstanding statement provides details of all partner's outstanding 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 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 refunds and outstanding payments. The list is displayed in chronological order and is
split by currencies." split by currencies.
for="" </span>
/>
<br /> <br />
<br /> <br />
</xpath> </xpath>
@ -105,15 +109,15 @@
<field name="inherit_id" ref="partner_statement.statement_common_view" /> <field name="inherit_id" ref="partner_statement.statement_common_view" />
<field name="mode">primary</field> <field name="mode">primary</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//div[@name='info']/label" position="before"> <xpath expr="//div[@name='info']/span" position="before">
<label <span
string="The activity statement provides details of all activity on 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, 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 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 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." displayed in chronological order and is split by currencies.
for="" </span>
/>
<br /> <br />
<br /> <br />
</xpath> </xpath>