from odoo import fields, models


class WooReturn(models.Model):
    _name = 'woo.return'
    _description = 'WooCommerce Return'

    instance_id = fields.Many2one('woo.instance', required=True, ondelete='cascade')
    order_id = fields.Many2one('woo.order', required=True)
    picking_id = fields.Many2one('stock.picking')
    reason = fields.Text()
    line_ids = fields.One2many('woo.return.line', 'return_id')
    state = fields.Selection([
        ('requested', 'Requested'),
        ('approved', 'Approved'),
        ('received', 'Received'),
        ('refunded', 'Refunded'),
        ('rejected', 'Rejected'),
    ], default='requested')
    company_id = fields.Many2one(
        'res.company', required=True, default=lambda self: self.env.company,
    )


class WooReturnLine(models.Model):
    _name = 'woo.return.line'
    _description = 'WooCommerce Return Line'

    return_id = fields.Many2one('woo.return', required=True, ondelete='cascade')
    product_id = fields.Many2one('product.product', required=True)
    quantity = fields.Float(default=1.0)
    reason = fields.Selection([
        ('defective', 'Defective'),
        ('wrong_item', 'Wrong Item'),
        ('not_needed', 'Not Needed'),
        ('damaged', 'Damaged'),
        ('other', 'Other'),
    ])
    company_id = fields.Many2one(
        'res.company', default=lambda self: self.env.company,
    )
