mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-21 23:32:09 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1,2 @@
|
|||
from . import geo_npa
|
||||
from . import retail_machine
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
# Copyright 2011-2012 Nicolas Bessi (Camptocamp SA)
|
||||
# Copyright 2023 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class NPA(models.Model):
|
||||
|
||||
"""GEO OSV SAMPLE"""
|
||||
|
||||
_name = "dummy.zip"
|
||||
_description = "Geoengine demo ZIP"
|
||||
|
||||
priority = fields.Integer(default=100)
|
||||
name = fields.Char("ZIP", index=True, required=True)
|
||||
city = fields.Char(index=True, required=True)
|
||||
the_geom = fields.GeoMultiPolygon("NPA Shape")
|
||||
# the_geom_poly = fields.GeoPolygon()
|
||||
# the_geom_multiLine = fields.GeoMultiLine()
|
||||
# the_geom_multipoint = fields.GeoMultiPoint()
|
||||
total_sales = fields.Float(
|
||||
compute="_compute_ZIP_total_sales",
|
||||
string="Spatial! Total Sales",
|
||||
)
|
||||
retail_machine_ids = fields.One2many(
|
||||
"geoengine.demo.automatic.retailing.machine",
|
||||
string="Retail machines",
|
||||
inverse_name="zip_id",
|
||||
)
|
||||
|
||||
def _compute_ZIP_total_sales(self):
|
||||
"""Return the total of the invoiced sales for this npa"""
|
||||
mach_obj = self.env["geoengine.demo.automatic.retailing.machine"]
|
||||
for rec in self:
|
||||
res = mach_obj.search(
|
||||
[
|
||||
(
|
||||
"the_point",
|
||||
"geo_intersect",
|
||||
{"dummy.zip.the_geom": [("id", "=", rec.id)]},
|
||||
)
|
||||
]
|
||||
)
|
||||
cursor = self.env.cr
|
||||
if res.ids:
|
||||
cursor.execute(
|
||||
"SELECT sum(total_sales) from"
|
||||
" geoengine_demo_automatic_retailing_machine "
|
||||
"where id in %s;",
|
||||
(tuple(res.ids),),
|
||||
)
|
||||
res = cursor.fetchone()
|
||||
if res:
|
||||
rec.total_sales = res[0] or 0.0
|
||||
else:
|
||||
rec.total_sales = 0.0
|
||||
else:
|
||||
rec.total_sales = 0.0
|
||||
|
||||
def name_get(self):
|
||||
res = []
|
||||
for rec in self:
|
||||
res.append((rec.id, "%s %s" % (rec.name, rec.city)))
|
||||
return res
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
# Copyright 2011-2016 Camptocamp SA
|
||||
# Copyright 2023 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class RetailMachine(models.Model):
|
||||
"""GEO OSV SAMPLE"""
|
||||
|
||||
_name = "geoengine.demo.automatic.retailing.machine"
|
||||
_description = "Geoengine demo retailing machine"
|
||||
|
||||
the_point = fields.GeoPoint("Coordinate")
|
||||
the_line = fields.GeoLine("Power supply line", index=True)
|
||||
total_sales = fields.Float("Total sale", index=True)
|
||||
money_level = fields.Char(index=True)
|
||||
state = fields.Selection([("hs", "HS"), ("ok", "OK")], index=True)
|
||||
name = fields.Char("Serial number", required=True)
|
||||
zip_id = fields.Many2one(
|
||||
"dummy.zip", compute="_compute_zip_id", store=True, readonly=False
|
||||
)
|
||||
|
||||
@api.constrains("the_point", "zip_id")
|
||||
def _check_the_point(self):
|
||||
"""Check if the point is place in the corresponding area."""
|
||||
if self.the_point and self.zip_id:
|
||||
for rec in self:
|
||||
zip_match = (
|
||||
self.env["dummy.zip"]
|
||||
.search(
|
||||
[
|
||||
("id", "=", self.zip_id.id),
|
||||
("the_geom", "geo_contains", rec.the_point),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
.ids
|
||||
)
|
||||
if not zip_match:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"The point must be placed in the corresponding "
|
||||
+ "area. (serial number: %s).",
|
||||
rec.name,
|
||||
)
|
||||
)
|
||||
|
||||
@api.depends("the_point")
|
||||
def _compute_zip_id(self):
|
||||
"""Exemple of on change on the point
|
||||
Lookup in zips if the code is within an area.
|
||||
Change the zip_id field accordingly
|
||||
"""
|
||||
for rec in self:
|
||||
if rec.the_point:
|
||||
zip_match = (
|
||||
self.env["dummy.zip"]
|
||||
.search([("the_geom", "geo_contains", rec.the_point)], limit=1)
|
||||
.ids
|
||||
)
|
||||
if zip_match:
|
||||
rec.zip_id = zip_match[0]
|
||||
else:
|
||||
rec.zip_id = 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue