model (relevant part):
class AcmeSapPricelist(models.Model):
_name = "acme.sap.pricelist"
_inherit = 'portal.mixin'
_description = "Some Model"
_order = 'date desc, id desc'
partner_id = fields.Many2one('res.partner', string='Partner', required=True)
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.user.company_id)
name = fields.Char(string='Document name')
origin = fields.Char(string='Document origin/source')
date = fields.Datetime(string='Document creation date')
note = fields.Char(string='Note')
file = fields.Many2one(comodel_name="ir.attachment", string="SAP file")
pricelist_lines = fields.One2many('acme.sap.pricelist.line', compute='_pricelist_lines', store=False)
@api.multi
def _pricelist_lines(self):
self.pricelist_lines = request.env['acme.sap.pricelist.line'].search([('sap_pricelist_id', '=', 1)])
view (relevant part):
<record id="view_acme_sap_pricelist_form" model="ir.ui.view">
<field name="name">acme.sap.pricelist.form</field>
<field name="model">acme.sap.pricelist</field>
<field name="priority" eval="8" />
<field name="arch" type="xml">
<form string="Pricelist">
<sheet>
<div class="oe_title">
<h1>
<field name="name"/>
</h1>
</div>
<group>
<group>
<field name="date"/>
<field name="id"/>
</group>
<group>
<field name="partner_id"/>
<field name="csv"/>
</group>
</group>
<group>
<group>
<field name="origin"/>
<field name="note"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
Above (file = fields.Many2one(comodel_name="ir.attachment", string="SAP file")) is writing a record to ir.attachment table, however I'm unable to figure how to get the columns
res_model
res_model_name
res_field
res_id
filled too. All of them are set to NULL when uploading an file making it impossible to process the record further.
Based on some testing, at least res_model (=>res.partner in this case) and res_id (=>the partners Id) would be required (i.e. for allowing a website user to access the attachment via /web/content/id). How can I tell my module to pass on these two?