File: ir.py

package info (click to toggle)
tryton-modules-product-cost-warehouse 7.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 424 kB
  • sloc: python: 731; xml: 58; makefile: 11; sh: 3
file content (39 lines) | stat: -rw-r--r-- 1,326 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelSQL, ModelView, dualmethod, fields
from trytond.pool import PoolMeta
from trytond.transaction import Transaction


class Cron(metaclass=PoolMeta):
    __name__ = 'ir.cron'
    warehouses = fields.Many2Many(
        'ir.cron-stock.warehouse', 'cron', 'warehouse',
        "Warehouses",
        domain=[
            ('type', '=', 'warehouse'),
            ],
        help="Warehouses registered for this cron.")

    @dualmethod
    @ModelView.button
    def run_once(cls, crons):
        for cron in crons:
            if not cron.warehouses:
                super().run_once([cron])
            else:
                for warehouse in cron.warehouses:
                    with Transaction().set_context(warehouse=warehouse.id):
                        super(Cron, cls).run_once([cron])


class CronWarehouse(ModelSQL):
    "Cron - Warehouse"
    __name__ = 'ir.cron-stock.warehouse'
    cron = fields.Many2One(
        'ir.cron', "Cron", ondelete='CASCADE', required=True)
    warehouse = fields.Many2One(
        'stock.location', "Warehouse", ondelete='CASCADE', required=True,
        domain=[
            ('type', '=', 'warehouse'),
            ])