Exemplo n.º 1
0
    def test_deserialize(self):
        cr, uid = self.cr, self.uid

        # Create partner
        vals = {
            'name': 'My Partner',
        }
        partner_id = self.partner.create(vals)

        # Create product
        vals = {
            'name': 'Product',
            'type': 'product',
            'purchase_ok': True,
            'default_code': 'P0001',
        }
        product_id = self.product.create(vals)

        # Create tk.json.pattern
        json_pattern = """
{
    "name": "SO Pattern",
    "url": "http://...",
    "realm": "realm",
    "login": "******",
    "password": "******",
    "model": "sale.order",
    "xpath": "Doc",
    "date_format": "format",
    "date_format_sent": "format",
    "fields": [
        {
            "xpath": "Doc/date"
        },
        {
            "multi": "True",
            "xpath": "Doc/SO",
            "fields": [
                {
                    "name": "amount_total",
                    "xpath": "Doc/SO/amount_total"
                },
                {
                    "name": "user_id",
                    "xpath": "Doc/SO/user_name",
                    "fields": [
                        {
                            "name": "login",
                            "xpath": "Doc/SO/user_name"
                        }
                    ]
                },
                {
                    "name": "partner_id",
                    "xpath": "Doc/SO/partner",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/partner"
                        }
                    ]
                },
                {
                    "name": "currency_id",
                    "xpath": "Doc/SO/currency",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/currency"
                        }
                    ]
                },
                {
                    "name": "pricelist_id",
                    "xpath": "Doc/SO/pricelist",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/pricelist"
                        }
                    ]
                },
                {
                    "name": "order_line",
                    "xpath": "Doc/SO/lines/line",
                    "fields": [
                        {
                            "name": "price_unit",
                            "xpath": "Doc/SO/lines/line/price_unit"
                        },
                        {
                            "name": "name",
                            "xpath": "Doc/SO/lines/line/name"
                        },
                        {
                            "name": "product_id",
                            "xpath": "Doc/SO/lines/line/default_code",
                            "fields": [
                                {
                                    "name": "default_code",
                                    "xpath": "Doc/SO/lines/line/default_code"
                                }
                              ]
                        }
                    ]
                }
            ]
        }
    ]
}
"""

        so_model_id = self.env['ir.model'].search([('model', '=', 'sale.order')])[0]
        pattern_id = self.json_pattern.create({'name': 'Simple SO Pattern',
                                               'model_id': so_model_id.id,
                                               'json_pattern': json_pattern})

        so_xml = """<Doc>
<SO>
    <amount_total>10</amount_total>
    <user_name>admin</user_name>
    <partner>My Partner</partner>
    <currency>EUR</currency>
    <pricelist>Public Pricelist</pricelist>
    <partner>My Partner</partner>
    <lines>
        <line>
            <name>Product</name>
            <default_code>P0001</default_code>
            <price_unit>5</price_unit>
        </line>
        <line>
            <name>Product</name>
            <default_code>P0001</default_code>
            <price_unit>15</price_unit>
        </line>
        <line>
            <name>Product</name>
            <default_code>P0001</default_code>
            <price_unit>25</price_unit>
        </line>
    </lines>
</SO>
</Doc>
"""

        so_id = serializer(cr, uid, pooler.get_pool(self.cr.dbname), pattern_id=pattern_id.id, xml=so_xml).deserialize_object()
        so = self.sale_order.browse(so_id)
        self.assertEqual(so.user_id.login, 'admin')
        self.assertEqual(len(so.order_line), 3)
        self.assertEqual(so.order_line[0].product_id.name, 'Product')
        self.assertEqual(so.order_line[0].product_id.default_code, 'P0001')
Exemplo n.º 2
0
 def deserialize(self, cr, uid, pattern_id, xml, strict=None, context=None):
     return serializer(cr, uid, self.pool, pattern_id=pattern_id, xml=xml).deserialize_object()
Exemplo n.º 3
0
    def test_serialize(self):
        cr, uid = self.cr, self.uid

        # Create partner
        vals = {
            'name': 'My Partner',
        }
        partner_id = self.partner.create(vals)

        # Create product
        vals = {
            'name': 'Product',
            'type': 'product',
            'purchase_ok': True,
            'default_code': 'P0001',
        }
        product_id = self.product.create(vals)

        # SO lines
        line = {
            'name': 'Product',
            'product_id': product_id.id,
        }

        # Create SO
        vals = {
            'partner_id': partner_id.id,
            'order_line': [[0, False, line], [0, False, line], [0, False, line]],
        }
        so = self.sale_order.create(vals)

        # Create tk.json.pattern
        json_pattern = """
{
    "name": "SO Pattern",
    "url": "http://...",
    "realm": "realm",
    "login": "******",
    "password": "******",
    "model": "sale.order",
    "xpath": "Doc",
    "date_format": "format",
    "date_format_sent": "format",
    "fields": [
        {
            "xpath": "Doc/date"
        },
        {
            "multi": "True",
            "xpath": "Doc/SO",
            "fields": [
                {
                    "name": "amount_total",
                    "xpath": "Doc/SO/amount_total"
                },
                {
                    "name": "user_id",
                    "xpath": "Doc/SO/user_name",
                    "fields": [
                        {
                            "name": "login",
                            "xpath": "Doc/SO/user_name"
                        }
                    ]
                },
                {
                    "name": "partner_id",
                    "xpath": "Doc/SO/partner",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/partner"
                        }
                    ]
                },
                {
                    "name": "currency_id",
                    "xpath": "Doc/SO/currency",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/currency"
                        }
                    ]
                },
                {
                    "name": "pricelist_id",
                    "xpath": "Doc/SO/pricelist",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/pricelist"
                        }
                    ]
                },
                {
                    "name": "order_line",
                    "xpath": "Doc/SO/lines/line",
                    "fields": [
                        {
                            "name": "price_unit",
                            "xpath": "Doc/SO/lines/line/price_unit"
                        },
                        {
                            "name": "name",
                            "xpath": "Doc/SO/lines/line/name"
                        },
                        {
                            "name": "product_id",
                            "xpath": "Doc/SO/lines/line/default_code",
                            "fields": [
                                {
                                    "name": "default_code",
                                    "xpath": "Doc/SO/lines/line/default_code"
                                }
                              ]
                        }
                    ]
                }
            ]
        }
    ]
}
"""
        so_model_id = self.env['ir.model'].search([('model', '=', 'sale.order')])[0]
        pattern_id = self.json_pattern.create({'name': 'Simple SO Pattern',
                                               'model_id': so_model_id.id,
                                               'json_pattern': json_pattern})
        xml = serializer(cr, uid, pooler.get_pool(self.cr.dbname), pattern_id=pattern_id.id).serialize_object(so.id)
        root = etree.parse(StringIO(xml))
        self.assertEqual(root.find('SO/user_name').text, 'admin')
        self.assertEqual(len(root.findall('SO/lines/line')), 3)
        self.assertEqual(root.findall('SO/lines/line[0]/default_code')[0].text, 'P0001')
Exemplo n.º 4
0
 def serialize(self, cr, uid, pattern_id, document_id, partner_id=None, preview=None, add_tag_if_empty=True, context=None):
     return serializer(cr, uid, self.pool, pattern_id=pattern_id, add_tag_if_empty=add_tag_if_empty).serialize_object(document_id)
Exemplo n.º 5
0
    def test_deserialize(self):
        cr, uid = self.cr, self.uid

        # Create partner
        vals = {
            'name': 'My Partner',
        }
        partner_id = self.partner.create(vals)

        # Create product
        vals = {
            'name': 'Product',
            'type': 'product',
            'purchase_ok': True,
            'default_code': 'P0001',
        }
        product_id = self.product.create(vals)

        # Create tk.json.pattern
        json_pattern = """
{
    "name": "SO Pattern",
    "url": "http://...",
    "realm": "realm",
    "login": "******",
    "password": "******",
    "model": "sale.order",
    "xpath": "Doc",
    "date_format": "format",
    "date_format_sent": "format",
    "fields": [
        {
            "xpath": "Doc/date"
        },
        {
            "multi": "True",
            "xpath": "Doc/SO",
            "fields": [
                {
                    "name": "amount_total",
                    "xpath": "Doc/SO/amount_total"
                },
                {
                    "name": "user_id",
                    "xpath": "Doc/SO/user_name",
                    "fields": [
                        {
                            "name": "login",
                            "xpath": "Doc/SO/user_name"
                        }
                    ]
                },
                {
                    "name": "partner_id",
                    "xpath": "Doc/SO/partner",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/partner"
                        }
                    ]
                },
                {
                    "name": "currency_id",
                    "xpath": "Doc/SO/currency",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/currency"
                        }
                    ]
                },
                {
                    "name": "pricelist_id",
                    "xpath": "Doc/SO/pricelist",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/pricelist"
                        }
                    ]
                },
                {
                    "name": "order_line",
                    "xpath": "Doc/SO/lines/line",
                    "fields": [
                        {
                            "name": "price_unit",
                            "xpath": "Doc/SO/lines/line/price_unit"
                        },
                        {
                            "name": "name",
                            "xpath": "Doc/SO/lines/line/name"
                        },
                        {
                            "name": "product_id",
                            "xpath": "Doc/SO/lines/line/default_code",
                            "fields": [
                                {
                                    "name": "default_code",
                                    "xpath": "Doc/SO/lines/line/default_code"
                                }
                              ]
                        }
                    ]
                }
            ]
        }
    ]
}
"""

        so_model_id = self.env['ir.model'].search([('model', '=', 'sale.order')
                                                   ])[0]
        pattern_id = self.json_pattern.create({
            'name': 'Simple SO Pattern',
            'model_id': so_model_id.id,
            'json_pattern': json_pattern
        })

        so_xml = """<Doc>
<SO>
    <amount_total>10</amount_total>
    <user_name>admin</user_name>
    <partner>My Partner</partner>
    <currency>EUR</currency>
    <pricelist>Public Pricelist</pricelist>
    <partner>My Partner</partner>
    <lines>
        <line>
            <name>Product</name>
            <default_code>P0001</default_code>
            <price_unit>5</price_unit>
        </line>
        <line>
            <name>Product</name>
            <default_code>P0001</default_code>
            <price_unit>15</price_unit>
        </line>
        <line>
            <name>Product</name>
            <default_code>P0001</default_code>
            <price_unit>25</price_unit>
        </line>
    </lines>
</SO>
</Doc>
"""

        so_id = serializer(cr,
                           uid,
                           pooler.get_pool(self.cr.dbname),
                           pattern_id=pattern_id.id,
                           xml=so_xml).deserialize_object()
        so = self.sale_order.browse(so_id)
        self.assertEqual(so.user_id.login, 'admin')
        self.assertEqual(len(so.order_line), 3)
        self.assertEqual(so.order_line[0].product_id.name, 'Product')
        self.assertEqual(so.order_line[0].product_id.default_code, 'P0001')
Exemplo n.º 6
0
    def test_serialize(self):
        cr, uid = self.cr, self.uid

        # Create partner
        vals = {
            'name': 'My Partner',
        }
        partner_id = self.partner.create(vals)

        # Create product
        vals = {
            'name': 'Product',
            'type': 'product',
            'purchase_ok': True,
            'default_code': 'P0001',
        }
        product_id = self.product.create(vals)

        # SO lines
        line = {
            'name': 'Product',
            'product_id': product_id.id,
        }

        # Create SO
        vals = {
            'partner_id': partner_id.id,
            'order_line': [[0, False, line], [0, False, line],
                           [0, False, line]],
        }
        so = self.sale_order.create(vals)

        # Create tk.json.pattern
        json_pattern = """
{
    "name": "SO Pattern",
    "url": "http://...",
    "realm": "realm",
    "login": "******",
    "password": "******",
    "model": "sale.order",
    "xpath": "Doc",
    "date_format": "format",
    "date_format_sent": "format",
    "fields": [
        {
            "xpath": "Doc/date"
        },
        {
            "multi": "True",
            "xpath": "Doc/SO",
            "fields": [
                {
                    "name": "amount_total",
                    "xpath": "Doc/SO/amount_total"
                },
                {
                    "name": "user_id",
                    "xpath": "Doc/SO/user_name",
                    "fields": [
                        {
                            "name": "login",
                            "xpath": "Doc/SO/user_name"
                        }
                    ]
                },
                {
                    "name": "partner_id",
                    "xpath": "Doc/SO/partner",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/partner"
                        }
                    ]
                },
                {
                    "name": "currency_id",
                    "xpath": "Doc/SO/currency",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/currency"
                        }
                    ]
                },
                {
                    "name": "pricelist_id",
                    "xpath": "Doc/SO/pricelist",
                    "fields": [
                        {
                            "name": "name",
                            "xpath": "Doc/SO/pricelist"
                        }
                    ]
                },
                {
                    "name": "order_line",
                    "xpath": "Doc/SO/lines/line",
                    "fields": [
                        {
                            "name": "price_unit",
                            "xpath": "Doc/SO/lines/line/price_unit"
                        },
                        {
                            "name": "name",
                            "xpath": "Doc/SO/lines/line/name"
                        },
                        {
                            "name": "product_id",
                            "xpath": "Doc/SO/lines/line/default_code",
                            "fields": [
                                {
                                    "name": "default_code",
                                    "xpath": "Doc/SO/lines/line/default_code"
                                }
                              ]
                        }
                    ]
                }
            ]
        }
    ]
}
"""
        so_model_id = self.env['ir.model'].search([('model', '=', 'sale.order')
                                                   ])[0]
        pattern_id = self.json_pattern.create({
            'name': 'Simple SO Pattern',
            'model_id': so_model_id.id,
            'json_pattern': json_pattern
        })
        xml = serializer(cr,
                         uid,
                         pooler.get_pool(self.cr.dbname),
                         pattern_id=pattern_id.id).serialize_object(so.id)
        root = etree.parse(StringIO(xml))
        self.assertEqual(root.find('SO/user_name').text, 'admin')
        self.assertEqual(len(root.findall('SO/lines/line')), 3)
        self.assertEqual(
            root.findall('SO/lines/line[0]/default_code')[0].text, 'P0001')
Exemplo n.º 7
0
 def deserialize(self, cr, uid, pattern_id, xml, strict=None, context=None):
     return serializer(cr, uid, self.pool, pattern_id=pattern_id, xml=xml).deserialize_object()
Exemplo n.º 8
0
 def serialize(
     self, cr, uid, pattern_id, document_id, partner_id=None, preview=None, add_tag_if_empty=True, context=None
 ):
     return serializer(
         cr, uid, self.pool, pattern_id=pattern_id, add_tag_if_empty=add_tag_if_empty
     ).serialize_object(document_id)