1.在__manifest__.py加入css文件路径
'css': ['static/src/css/ab.css'],
2.定义css文件
.ted
{
background-color: #fff;
font-size: 36px;
}
.fss
{
color:red !important;
}
3.定义测试字段
# -*- coding: utf-8 -*-
from odoo import api, fields, models, _
class ZfyStockPicking(models.Model):
_inherit = 'stock.picking'
abc = fields.Char(u'测试字段颜色')
4.在xml文件中引入css文件,及新增测试字段用以测试
<template id="assets_backend" inherit_id="web.assets_backend" name="zfy_assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" type="text/css" href="/css_test/static/src/css/ab.css"/>
</xpath>
</template>
<record id="view_stock_picking_form_inherit" model="ir.ui.view">
<field name="name">view_stock_picking_form_inherit</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="abc" class="fss"/>
</field>
</field>
</record>
效果如图:
如果在pdf中,也可以直接定义在template中定义css,然后引用
<template id="stock_picking_report1">
<style type="text/css">
.ssgt
{
color: red;
}
table.pptg
{
color: blue;
}
</style>
<t t-call="report.html_container">
<div class="page ssgt">
<div class="row">
<div class="col-xs-4">
<strong>单据号:</strong>
<p t-esc="docs.name"/>
</div>
</div>
<table class="table pptg">
<thead>
<tr>
<th>行号</th>
<th>产品名称</th>
</tr>
</thead>
<tbody>
<tr style="page-break-inside : avoid"
t-foreach="docs.move_lines" t-as="lot">
<td>
<span t-esc="lot.product_id.display_name"/>
</td>
<td>
<span t-esc="lot.product_uom_qty"/>
</td>
</tr>
</tbody>
</table>
</div>
</t>
</template>
效果如图: