<commit_before># -*- coding: utf-8 -*-
# © 2011 <NAME> <<EMAIL>>
# © 2013 Camptocamp SA (author: <NAME>)
# © 2016 Sodexis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields, api


class SaleWorkflowProcess(models.Model):
    """ A workflow process is the setup of the automation of a sales order.

    Each sales order can be linked to a workflow process.
    Then, the options of the workflow will change how the sales order
    behave, and how it is automatized.

    A workflow process may be linked with a Sales payment method, so
    each time a payment method is used, the workflow will be applied.
    """
    _name = "sale.workflow.process"
    _description = "Sale Workflow Process"

    name = fields.Char()
    picking_policy = fields.Selection(
        selection=[('direct', 'Deliver each product when available'),
                   ('one', 'Deliver all products at once')],
        string='Shipping Policy',
        default='direct',
    )
    validate_order = fields.Boolean(string='Validate Order')
    order_filter_domain = fields.Char(
        string='Order Filter Domain',
        default="[('state', '=', 'draft')]"
    )
    create_invoice = fields.Boolean(string='Create Invoice')
    create_invoice_filter_domain = fields.Char(
        string='Create Invoice Filter Domain',
        default="[('state','in',['sale','done']),"
        "('invoice_status','=','to invoice')]"
    )
    validate_invoice = fields.Boolean(string='Validate Invoice')
    validate_invoice_filter_domain = fields.Char(
        string='Validate Invoice Filter Domain',
        default="[('state', '=', 'draft')]"
    )
    validate_picking = fields.Boolean(string='Confirm and Transfer Picking')
    picking_filter_domain = fields.Char(
        string='Picking Filter Domain',
        default="[('state', 'in', ['draft', 'confirmed', 'assigned'])]"
    )
    invoice_date_is_order_date = fields.Boolean(
        string='Force Invoice Date',
        help="When checked, the invoice date will be "
             "the same than the order's date"
    )

    sale_done = fields.Boolean(string='Sale Done')
    sale_done_filter_domain = fields.Char(
        string='Sale Done Filter Domain',
        default="[('state', '=', 'sale'),('invoice_status','=','invoiced')]"
    )
    warning = fields.Text(
        'Warning Message', translate=True,
        help='If set, displays the message when an user'
        'selects the process on a sale order')
    team_id = fields.Many2one(
        comodel_name='crm.team',
        string='Sales Team'
    )
    property_journal_id = fields.Many2one(
        comodel_name='account.journal',
        company_dependent=True,
        string='Sales Journal',
        help='Set default journal to use on invoice'
    )
    order_filter_id = fields.Many2one(
        'ir.filters',
        string='Order Filter',
        default=lambda self: self.env.ref(
            'sale_automatic_workflow.automatic_workflow_order_filter')
    )
    picking_filter_id = fields.Many2one(
        'ir.filters',
        string='Picking Filter',
        default=lambda self: self.env.ref(
            'sale_automatic_workflow.automatic_workflow_picking_filter')
    )
    create_invoice_filter_id = fields.Many2one(
        'ir.filters',
        string='Create Invoice Filter',
        default=lambda self: self.env.ref(
            'sale_automatic_workflow.automatic_workflow_create_invoice_filter')
    )
    validate_invoice_filter_id = fields.Many2one(
        'ir.filters',
        string='Validate Invoice Filter',
        default=lambda self: self.env.ref(
            'sale_automatic_workflow.'
            'automatic_workflow_validate_invoice_filter')
    )
    sale_done_filter_id = fields.Many2one(
        'ir.filters',
        string='Sale Done Filter',
        default=lambda self: self.env.ref(
            'sale_automatic_workflow.automatic_workflow_sale_done_filter')
    )

    @api.onchange('order_filter_id')
    def onchange_order_filter_id(self):
        if self.order_filter_id:
            self.order_filter_domain = self.order_filter_id.domain

    @api.onchange('picking_filter_id')
    def onchange_picking_filter_id(self):
        if self.picking_filter_id:
            self.picking_filter_domain = self.picking_filter_id.domain

    @api.onchange('create_invoice_filter_id')
    def onchange_create_invoice_filter_id(self):<commit_msg>Fix default filters<commit_after># -*- coding: utf-8 -*-
# © 2011 <NAME> <<EMAIL>>
# © 2013 Camptocamp SA (author: <NAME>)
# © 2016 Sodexis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields, api


class SaleWorkflowProcess(models.Model):
    """ A workflow process is the setup of the automation of a sales order.

    Each sales order can be linked to a workflow process.
    Then, the options of the workflow will change how the sales order
    behave, and how it is automatized.

    A workflow process may be linked with a Sales payment method, so
    each time a payment method is used, the workflow will be applied.
    """
    _name = "sale.workflow.process"
    _description = "Sale Workflow Process"

    @api.model
    def _default_filter(self, xmlid):
        record = self.env.ref(xmlid, raise_if_not_found=False)
        if record:
            return record
        return self.env['ir.filters'].browse()

    name = fields.Char()
    picking_policy = fields.Selection(
        selection=[('direct', 'Deliver each product when available'),
                   ('one', 'Deliver all products at once')],
        string='Shipping Policy',
        default='direct',
    )
    validate_order = fields.Boolean(string='Validate Order')
    order_filter_domain = fields.Char(
        string='Order Filter Domain',
        default="[('state', '=', 'draft')]"
    )
    create_invoice = fields.Boolean(string='Create Invoice')
    create_invoice_filter_domain = fields.Char(
        string='Create Invoice Filter Domain',
        default="[('state','in',['sale','done']),"
        "('invoice_status','=','to invoice')]"
    )
    validate_invoice = fields.Boolean(string='Validate Invoice')
    validate_invoice_filter_domain = fields.Char(
        string='Validate Invoice Filter Domain',
        default="[('state', '=', 'draft')]"
    )
    validate_picking = fields.Boolean(string='Confirm and Transfer Picking')
    picking_filter_domain = fields.Char(
        string='Picking Filter Domain',
        default="[('state', 'in', ['draft', 'confirmed', 'assigned'])]"
    )
    invoice_date_is_order_date = fields.Boolean(
        string='Force Invoice Date',
        help="When checked, the invoice date will be "
             "the same than the order's date"
    )

    sale_done = fields.Boolean(string='Sale Done')
    sale_done_filter_domain = fields.Char(
        string='Sale Done Filter Domain',
        default="[('state', '=', 'sale'),('invoice_status','=','invoiced')]"
    )
    warning = fields.Text(
        'Warning Message', translate=True,
        help='If set, displays the message when an user'
        'selects the process on a sale order')
    team_id = fields.Many2one(
        comodel_name='crm.team',
        string='Sales Team'
    )
    property_journal_id = fields.Many2one(
        comodel_name='account.journal',
        company_dependent=True,
        string='Sales Journal',
        help='Set default journal to use on invoice'
    )
    order_filter_id = fields.Many2one(
        'ir.filters',
        string='Order Filter',
        default=lambda self: self._default_filter(
            'sale_automatic_workflow.automatic_workflow_order_filter'
        )
    )
    picking_filter_id = fields.Many2one(
        'ir.filters',
        string='Picking Filter',
        default=lambda self: self._default_filter(
            'sale_automatic_workflow.automatic_workflow_picking_filter'
        )
    )
    create_invoice_filter_id = fields.Many2one(
        'ir.filters',
        string='Create Invoice Filter',
        default=lambda self: self._default_filter(
            'sale_automatic_workflow.automatic_workflow_create_invoice_filter'
        )
    )
    validate_invoice_filter_id = fields.Many2one(
        'ir.filters',
        string='Validate Invoice Filter',
        default=lambda self: self._default_filter(
            'sale_automatic_workflow.'
            'automatic_workflow_validate_invoice_filter'
        )
    )
    sale_done_filter_id = fields.Many2one(
        'ir.filters',
        string='Sale Done Filter',
        default=lambda self: self._default_filter(
            'sale_automatic_workflow.automatic_workflow_sale_done_filter'
        )
    )

    @api.onchange('order_filter_id')
    def onchange_order_filter_id(self):
        if self.order_filter_id:
            self.order_filter_domain = self.order_filter_id.domain

    @api.onchange('picking_filter_id')
    def onchange_picking_filter_id(self):
        if self.picking_filter_id:
            self.picking_filter_domain = self.picking_filter_id.domain

    @api.onchange('create_invoice_filter_id')
    def onchange_create_invoice_filter_id(self):
{'fraction_non_alphanumeric': 0.11208406304728546, 'fraction_numerical': 0.004816112084063047, 'mean_word_length': 2.9622723330442327, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6342140', 'n_tokens_mistral': 2793, 'n_tokens_neox': 2654, 'n_words': 614}