Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.0] pos_invoice_pay: store POS session in payment record #1457

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pos_invoice_pay/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"summary": """Handle the payment process for Sale Orders/Invoices over Point of Sale""",
"category": "Point of Sale",
"images": ["images/pos_invoice_pay_main.png"],
"version": "10.0.1.0.6",
"version": "10.0.1.1.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше капитально поменять версию, т.к. там поля добавляются и нужно нажимать "Обновить модуль"

Suggested change
"version": "10.0.1.1.0",
"version": "10.0.2.0.0",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

там поля добавляются и нужно нажимать "Обновить модуль"

https://gitlab.com/itpp/handbook/-/blob/master/technical-docs/__manifest__.md#version

The x.y.z version numbers follow the semantics breaking.feature.fix:

  • x increments when the data model or the views had significant
    changes. Data migration might be needed, or depending modules might
    be affected.
  • y increments when non-breaking new features are added. A module
    upgrade will probably be needed.

Попадает под y.

"application": False,
"author": "IT-Projects LLC, Artyom Losev",
"support": "apps@itpp.dev",
Expand Down
5 changes: 5 additions & 0 deletions pos_invoice_pay/doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
`1.1.0`
-------

**Improvement:** Store POS session in payment record

`1.0.6`
-------

Expand Down
17 changes: 15 additions & 2 deletions pos_invoice_pay/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2018 Artyom Losev
# Copyright 2018 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
# Copyright 2021 Eugene Molotov <https://github.com/em230418>
# License MIT (https://opensource.org/licenses/MIT).

from odoo import api, fields, models
Expand Down Expand Up @@ -49,7 +50,7 @@ def process_invoice_payment(self, invoice):
"partner_type": "customer",
"payment_difference_handling": payment_difference_handling,
"writeoff_account_id": writeoff_acc_id,
"paid_by_pos": True,
"pos_session_id": invoice["data"]["pos_session_id"],
"cashier": cashier,
}
payment = self.env["account.payment"].create(vals)
Expand All @@ -66,9 +67,15 @@ def process_invoices_creation(self, sale_order_id):
class AccountPayment(models.Model):
_inherit = "account.payment"

paid_by_pos = fields.Boolean(default=False)
paid_by_pos = fields.Boolean(compute="_compute_paid_by_pos", store=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если поле не используется для поиска\фильтрации, то не обязательно сохранять в таблице значения

Suggested change
paid_by_pos = fields.Boolean(compute="_compute_paid_by_pos", store=True)
paid_by_pos = fields.Boolean(compute="_compute_paid_by_pos")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это поле используется для поиска

payments = self.env["account.payment"].search(
[
("payment_date", ">=", date_start),
("payment_date", "<=", date_stop),
("paid_by_pos", "=", True),
]
)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может напрямую по новому полю искать?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может напрямую по новому полю искать?

Действительно можно, но дело в другом. Если какой-то сторонний модуль зависит от этого модуля и использует paid_by_pos, который изначально в базе хранится, то этот сторонний модуль сломается.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может сторонний модуль сделает store=True ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ладно, я устал спорить. Просто обозначу как 10.0.2.0.0 и без store=True.

pos_session_id = fields.Many2one("pos.session")
cashier = fields.Many2one("res.users")

@api.depends("pos_session_id")
def _compute_paid_by_pos(self):
for record in self:
record.paid_by_pos = bool(record.pos_session_id.id)


class AccountInvoice(models.Model):
_inherit = "account.invoice"
Expand Down Expand Up @@ -171,3 +178,9 @@ class PosConfig(models.Model):
help="Ask for a cashier when fetch orders",
defaul=True,
)


class PosSession(models.Model):
_inherit = "pos.session"

invoice_payment_ids = fields.One2many("account.payment", "pos_session_id")