Skip to content

Commit

Permalink
Merge pull request #1 from acsone/16.0-mig-account_payment_order
Browse files Browse the repository at this point in the history
[IMP] create with @api.model_create_multi tag
  • Loading branch information
wpichler authored Feb 18, 2023
2 parents 9b437af + fdf2141 commit 4711bf7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def _insert_account_payments(env):
openupgrade.logged_query(
env.cr, "ALTER TABLE account_payment ADD old_bank_payment_line_id INT4"
)
openupgrade.logged_query(
env.cr, "ALTER TABLE account_payment ADD old_bank_payment_line_name text"
)
# Create an account.payment record for each bank.payment.line
openupgrade.logged_query(
env.cr,
Expand Down Expand Up @@ -161,6 +164,18 @@ def _insert_payment_line_payment_link(env):

@openupgrade.migrate()
def migrate(env, version):
env.cr.execute(
"""
SELECT column_name
FROM information_schema.columns
WHERE table_name='account_payment' and column_name='old_bank_payment_line_id'
"""
)

if len(env.cr.fetchall()) > 0:
# scripts have already been applied because column old_bank_payment_line_id exist
return

openupgrade.logged_query(
env.cr, "ALTER TABLE account_payment ALTER move_id DROP NOT NULL"
)
Expand Down
16 changes: 9 additions & 7 deletions account_payment_order/models/account_payment_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ class AccountPaymentLine(models.Model):
)
]

@api.model
def create(self, vals):
if vals.get("name", "New") == "New":
vals["name"] = (
self.env["ir.sequence"].next_by_code("account.payment.line") or "New"
)
return super(AccountPaymentLine, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("name", "New") == "New":
vals["name"] = (
self.env["ir.sequence"].next_by_code("account.payment.line")
or "New"
)
return super(AccountPaymentLine, self).create(vals_list)

@api.depends("amount_currency", "currency_id", "company_currency_id", "date")
def _compute_amount_company_currency(self):
Expand Down
34 changes: 18 additions & 16 deletions account_payment_order/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,24 @@ def _compute_move_count(self):
for order in self:
order.move_count = mapped_data.get(order.id, 0)

@api.model
def create(self, vals):
if vals.get("name", "New") == "New":
vals["name"] = (
self.env["ir.sequence"].next_by_code("account.payment.order") or "New"
)
if vals.get("payment_mode_id"):
payment_mode = self.env["account.payment.mode"].browse(
vals["payment_mode_id"]
)
vals["payment_type"] = payment_mode.payment_type
if payment_mode.bank_account_link == "fixed":
vals["journal_id"] = payment_mode.fixed_journal_id.id
if not vals.get("date_prefered") and payment_mode.default_date_prefered:
vals["date_prefered"] = payment_mode.default_date_prefered
return super(AccountPaymentOrder, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("name", "New") == "New":
vals["name"] = (
self.env["ir.sequence"].next_by_code("account.payment.order")
or "New"
)
if vals.get("payment_mode_id"):
payment_mode = self.env["account.payment.mode"].browse(
vals["payment_mode_id"]
)
vals["payment_type"] = payment_mode.payment_type
if payment_mode.bank_account_link == "fixed":
vals["journal_id"] = payment_mode.fixed_journal_id.id
if not vals.get("date_prefered") and payment_mode.default_date_prefered:
vals["date_prefered"] = payment_mode.default_date_prefered
return super(AccountPaymentOrder, self).create(vals_list)

@api.onchange("payment_mode_id")
def payment_mode_id_change(self):
Expand Down
28 changes: 7 additions & 21 deletions account_payment_order/report/account_payment_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,13 @@
<div class="oe_structure" />
<div class="row">
<div class="col-4 offset-8">
<span
t-raw="'%s &lt;br&gt;' % doc.journal_id.bank_id.name if doc.journal_id.bank_id.name else ''"
/>
<span
t-raw="'%s &lt;br&gt;' % doc.journal_id.bank_id.street if doc.journal_id.bank_id.street else ''"
/>
<span
t-raw="'%s &lt;br&gt;' % doc.journal_id.bank_id.street2 if doc.journal_id.bank_id.street2 else ''"
/>
<span
t-raw="'%s &lt;br&gt;' % doc.journal_id.bank_id.zip if doc.journal_id.bank_id.zip else ''"
/>
<span
t-raw="'%s &lt;br&gt;' % doc.journal_id.bank_id.city if doc.journal_id.bank_id.city else ''"
/>
<span
t-raw="'%s &lt;br&gt;' % doc.journal_id.bank_id.state.name if doc.journal_id.bank_id.state.name else ''"
/>
<span
t-raw="'%s &lt;br&gt;' % doc.journal_id.bank_id.country.name if doc.journal_id.bank_id.country.name else ''"
/>
<div t-field="doc.journal_id.bank_id.name" />
<div t-field="doc.journal_id.bank_id.street" />
<div t-field="doc.journal_id.bank_id.treet2" />
<div t-field="doc.journal_id.bank_id.zip" />
<div t-field="doc.journal_id.bank_id.city" />
<div t-field="doc.journal_id.bank_id.state.name" />
<div t-field="doc.journal_id.bank_id.country.name" />
</div>
</div>
<t t-if="doc.payment_type == 'inbound'">
Expand Down
2 changes: 1 addition & 1 deletion account_payment_order/views/account_payment_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<form string="Payment Lines">
<group name="main" col="2">
<group name="left">
<field name="company_id" invisible="1" />
<field
name="order_id"
groups="base.group_multi_company"
invisible="not context.get('account_payment_line_main_view')"
/>
<field name="name" />
Expand Down

0 comments on commit 4711bf7

Please sign in to comment.