Created
August 11, 2022 10:19
-
-
Save em230418/b59f020c4e2b2b91bff563d5da1a61f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from odoo import api, fields, models | |
class PosInvoiceReport(models.Model): | |
_inherit = "pos.invoice.report" | |
sales_per_invoice_count = fields.Float( | |
group_operator="SUM(price_subtotal)/COUNT(DISTINCT inv_id)+", | |
string="Sales per invoice count", | |
) | |
@api.model | |
def read_group(self, domain, fields, *args, **kw): | |
# вытаскиваю group_operator со своего поля, чтобы Odoo его не проверял | |
# этот group_operator все равно будет использоваться без проверки в дальнейшем | |
fields = list(map( | |
lambda x: x if x.split(":")[0] != "sales_per_invoice_count" else "sales_per_invoice_count", | |
fields | |
)) | |
return super(PosInvoiceReport, self).read_group(domain, fields, *args, **kw) | |
@api.model | |
def _inherits_join_calc(self, alias, fname, query): | |
if fname == "sales_per_invoice_count": | |
return "0" # строка с ноликом будет объеденяться с group_operator | |
return super(PosInvoiceReport, self)._inherits_join_calc(alias, fname, query) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment