<commit_before># -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in module root
# directory
##############################################################################
from openerp import models, fields, api


class website_promotion(models.Model):
    _name = 'website.promotion'
    _description = 'Website Promotion'

    name = fields.Char(
        'Name',
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]}
    )
    pricelist_id = fields.Many2one(
        'product.pricelist',
        'Pricelist',
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]}
    )
    public_category_id = fields.Many2one(
        'product.public.category',
        'Public Category',
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]}

    )
    template_ids = fields.Many2many(
        'product.template',
        'website_promotion_product_rel',
        'website_promotion_id',
        'product_id',
        'Product Template',
        readonly=True,
        states={'draft': [('readonly', False)]}
    )
    website_style_id = fields.Many2one(
        'product.style',
        'Website Style',
        readonly=True,
        states={'draft': [('readonly', False)]}
    )
    state = fields.Selection(
        [('draft', 'Draft'),
         ('confirm', 'Confirm'),
         ('finished', 'Finished')
         ],
        default='draft',
        string='State'
    )
    base = fields.Selection([
        ('list_price', 'Public Price'),
        ('standard_price', 'Cost'),
        ('pricelist', 'Other Pricelist')],
        'Based on',
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]}
    )
    price_discount = fields.Float(
        'Price Discount',
        readonly=True,
        states={'draft': [('readonly', False)]})
    price_surcharge = fields.Float(
        'Price Surcharge',
        readonly=True,
        states={'draft': [('readonly', False)]})
    base_pricelist_id = fields.Many2one(
        'product.pricelist',
        'Other Pricelist',
        readonly=True,
        states={'draft': [('readonly', False)]})

    @api.one
    def to_draft(self):
        self.state = 'draft'

    @api.one
    def confirm(self):
        self.state = 'confirm'
        if self.website_style_id:
            self.template_ids.write(
                {'website_style_ids': [(4, self.website_style_id.id)]})
        self.template_ids.write(
            {'public_categ_ids': [(4, self.public_category_id.id)]})
        for product in self.template_ids:
            vals = {
                'name': self.name,
                'product_tmpl_id': product.id,
                'sequence': 0,
                'base': self.base,
                'base_pricelist_id': self.base_pricelist_id.id,
                'pricelist_id': self.pricelist_id.id,<commit_msg>[FIX] set 'applied_on' value when create a pricelist item (#55)<commit_after># -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in module root
# directory
##############################################################################
from openerp import models, fields, api


class website_promotion(models.Model):
    _name = 'website.promotion'
    _description = 'Website Promotion'

    name = fields.Char(
        'Name',
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]}
    )
    pricelist_id = fields.Many2one(
        'product.pricelist',
        'Pricelist',
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]}
    )
    public_category_id = fields.Many2one(
        'product.public.category',
        'Public Category',
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]}

    )
    template_ids = fields.Many2many(
        'product.template',
        'website_promotion_product_rel',
        'website_promotion_id',
        'product_id',
        'Product Template',
        readonly=True,
        states={'draft': [('readonly', False)]}
    )
    website_style_id = fields.Many2one(
        'product.style',
        'Website Style',
        readonly=True,
        states={'draft': [('readonly', False)]}
    )
    state = fields.Selection(
        [('draft', 'Draft'),
         ('confirm', 'Confirm'),
         ('finished', 'Finished')
         ],
        default='draft',
        string='State'
    )
    base = fields.Selection([
        ('list_price', 'Public Price'),
        ('standard_price', 'Cost'),
        ('pricelist', 'Other Pricelist')],
        'Based on',
        required=True,
        readonly=True,
        states={'draft': [('readonly', False)]}
    )
    price_discount = fields.Float(
        'Price Discount',
        readonly=True,
        states={'draft': [('readonly', False)]})
    price_surcharge = fields.Float(
        'Price Surcharge',
        readonly=True,
        states={'draft': [('readonly', False)]})
    base_pricelist_id = fields.Many2one(
        'product.pricelist',
        'Other Pricelist',
        readonly=True,
        states={'draft': [('readonly', False)]})

    @api.one
    def to_draft(self):
        self.state = 'draft'

    @api.one
    def confirm(self):
        self.state = 'confirm'
        if self.website_style_id:
            self.template_ids.write(
                {'website_style_ids': [(4, self.website_style_id.id)]})
        self.template_ids.write(
            {'public_categ_ids': [(4, self.public_category_id.id)]})
        for product in self.template_ids:
            vals = {
                'name': self.name,
                'applied_on': '1_product',
                'product_tmpl_id': product.id,
                'sequence': 0,
                'base': self.base,
                'base_pricelist_id': self.base_pricelist_id.id,
                'pricelist_id': self.pricelist_id.id,
{'fraction_non_alphanumeric': 0.1883868863154461, 'fraction_numerical': 0.0034252161148262926, 'mean_word_length': 2.311015118790497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6641156', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1736, 'n_words': 340}